Gradle Could not create service of type InitScriptHandler using BuildScopeServices.createInitScriptHandler()

后端 未结 22 1920
囚心锁ツ
囚心锁ツ 2020-12-05 03:39

I used gradle build command in Centos 7 terminal and I got output:

FAILURE: Build failed with an exception.

* What we         


        
22条回答
  •  时光说笑
    2020-12-05 04:25

    Try setting your GRADLE_USER_HOME variable to a folder where you have valid access. Then this error will go away.

    For ex: I faced the same issue today while I was running gradle clean command on a new slave machine.

    My Gradle version was 2.3.

    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).

    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).

    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.

    Setting:

    GRADLE_USER_HOME=~/gradle_2_3_cache/.gradle
    

    resolved the issue.

    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.

    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

提交回复
热议问题