最近将CI改为了使用docker构建,gradle突然出现报错
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
一般来说出现这样的问题,大部分是内存不足问题,但此次肯定不是,可用内存大把。
于是google之,看了几种说法,感觉都不是,在翻stackoverflow的时候发现一个相关回复:
In our case the issue was caused by the CI server passing environment variables with non-ascii characters (i.e. in the names of commit authors).
Adding file.encoding=utf-8 to Gradle properties fixed the issue immediately.
瞬时觉得就是它了,于是返回去仔细查看gradle报错信息,发现如下内容
00:52:04.181 [DEBUG] [org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment] Configuring env variables: {CI_COMMIT_MESSAGE=????????????????????????????????????, PATH=/root/workspace/jdk/bin:/root/workspace/gradle/bin:/usr/local/sbin:/usr/local/
...
----- End of the daemon log -----
果然,是commit message里存在中文信息,导致CI Server传递环境变量时不能正确识别,导致出错。
方向找到了,就好解决了,需要从两个方面入手,一是让容器里的locale变成utf-8,另一方面是让gradle支持utf-8
一、进入到gradle容器中,确认了一下gradle容器中的locale
# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
是POSIX,不是UTF8,修改locale配置
# vi ~/.bash_profile
export LC_ALL="C.UTF-8"
export LANG="C.UTF-8"
export LANGUAGE="C.UTF-8"
二、导出修改过的容器,打tag,上传私仓
docker ps
docker export -o gradle.tar xxxxxxx
docker import gradle.tar harbor.demo.com/gradle:latest
docker push harbor.demo.com/gradle:latest
三、修改CI文件,让gradle支持utf-8
variables:
GRADLE_OPTS: "-Dfile.encoding=utf-8"
经过测试,问题解决。
参考文档:
/questions/37171043/gradle-build-daemon-disappeared-unexpectedly-it-may-have-been-killed-or-may-hav
/questions/21267234/show-utf-8-text-properly-in-gradle