Gradle无法使用BuildScopeServices.createInitScriptHandler()创建InitScriptHandler类型的服务
我在Centos 7终端中使用了gradle build命令,并得到了输出:
I used gradle build command in Centos 7 terminal and I got output:
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type InitScriptHandler using BuildScopeServices.createInitScriptHandler().
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
尝试将GRADLE_USER_HOME
变量设置为具有有效访问权限的文件夹.然后此错误将消失.
Try setting your GRADLE_USER_HOME
variable to a folder where you have valid access. Then this error will go away.
例如:在新的从属计算机上运行gradle clean
命令时,今天我遇到了同样的问题.
For ex: I faced the same issue today while I was running gradle clean
command on a new slave machine.
我的Gradle版本是2.3.
My Gradle version was 2.3.
使用--stacktrace,我知道它正在尝试创建用于存储Gradle缓存数据的.gradle
文件夹(当我调用Gradle在从属服务器上运行干净任务时),并且试图在下创建该文件夹. >/some/location/where/gradle/exists 或某些/path/location/xxx/yyy,其中在从属计算机上运行Gradle的用户没有有效的写权限(创建文件夹/文件) .
With --stacktrace, I came to know it was trying to create .gradle
folder for storing Gradle's cache data (while I invoked Gradle to run clean task on the slave) and it was trying to create that folder under /some/location/where/gradle/exists OR some /path/location/xxx/yyy where the user which was running Gradle on the slave machine didn't have valid access to write (create folder/files).
即我以前从Jenkins机器连接到从属服务器的用户在默认位置(Gradle认为可以的,我应该在这里创建.gradle文件夹)中没有任何权限对touch
/mkdir
进行任何写操作.
i.e. the user which I used to connect from Jenkins machine to the slave didn't have write access to touch
/mkdir
anything in the default location (where Gradle thought, OK I should create .gradle folder here).
要修复此问题,我在从站的环境变量"部分中添加了上述GRADLE_USER_HOME
变量.现在,由于我在主目录中具有有效的访问权限,所以我很好.
To fix it, I added the above GRADLE_USER_HOME
variable in the slave's ENVIRONMENT Variable section. Now, as I have valid access in my home directory, I was OK.
设置:
GRADLE_USER_HOME=~/gradle_2_3_cache/.gradle
解决了这个问题.
您也可以将其设置为〜/.gradle.但是我将其设置在~
主目录(gradle_2_3_cache)内的自定义文件夹下.如果我在同一台从属计算机上运行另一个作业/构建,但具有不同的Gradle版本(例如:2.5等版本),并且如果我想在单独的文件夹中为2.3和2.5/x版本的.gradle
缓存,这将对我有帮助
You can set it to ~/.gradle as well. But I set it under a custom folder inside my ~
home directory (gradle_2_3_cache). This will help me in case I have another job/build run running on the same Slave machine but with a different Gradle version for ex: 2.5 etc version and if I want the .gradle
cache for 2.3 and 2.5/x version in separate folders.
注意::在Jenkinsfile
中使用parallel
部分时,最好避免使用Gradle的功能(即使用相同的Gradle缓存,即使用相同的GRADLE_USER_HOME),否则,您将进入地雷此处列出的有趣问题: Jenkins-Java .lang.IllegalArgumentException:最后一个单元没有足够的有效位& Gradle错误:在根项目中找不到任务'null'
NOTE: When using parallel
section within Jenkinsfile
, it's best to avoid Gradle greatness (i.e. using same Gradle's cache i.e. using same GRADLE_USER_HOME) as otherwise, you'll land into a mine of interesting issues as listed here: Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits & Gradle error: Task 'null' not found in root project