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.
One way to upgrade the Gradle version is manually change the distributionUrl property in the Wrapper's gradle-wrapper. properties file. The better and recommended option is to run the wrapper task and provide the target Gradle version as described in Adding the Gradle Wrapper.
Method 1. Then just click on Build, Execution, Deployment Tab Build → Tools → Gradle → Use default Gradle wrapper (recommended) option. Step 2: Selecting desired Gradle version. Then click on the Project option.
The content of gradle-wrapper properties file is as follows: distributionBase=GRADLE_USER_HOME. distributionPath=wrapper/dists. distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip.
In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here. If you are using the Gradle wrapper, then your project will have a gradle/wrapper/gradle-wrapper.
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
For me, killing the Gradle daemon (gradle --stop
) really helped and fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With