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

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.

enter image description here

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


For me, killing the Gradle daemon (gradle --stop) really helped and fixed the issue.


The Problem solved by simply using "sudo" and giving access to gradle to create a folder and write cache. use:

sudo ./gradlew

Tags:

Gradle