Gradle Could not create service of type InitScript

2019-01-23 14:05发布

问题:

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.

回答1:

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 slave running on the same Slave machine but with 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.



回答2:

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



回答3:

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

sudo ./gradlew


回答4:

I had the same problem. For me it worked after I exclude the .gradle folder if you can not delete try to rename.



回答5:

If you using wrapper gradlew, in root make directory .gradle_new

mkdir .gradle_new
chmod -R 777 .gradle_new

and run gradlew with arguments:

--project-cache-dir .gradle_new


回答6:

If you have just updated your JDK version and you have set up a Gradle wrapper in your project, you may want to double-check the wrapper version supports your new JDK. If not, consider removing wrapper-related files from the project (gradlew, gradlew.bat and gradle/wrapper/*) and re-generating them with the Gradle CLI, like so:

gradle wrapper --gradle-version <new-version-number>

e.g. gradle wrapper --gradle-version 4.10.2

This of course assumes your Gradle installation is up-to-date. If not, you will want to update that first.



回答7:

You Just Have to Run it under the super user (sudo ....) it works for me



回答8:

For future reference. I had the same problem, the issue was that the antivirus was blocking OpenJdk platform binary and java.exe which prevented android studio from being able to modify the files



回答9:

I ran into this exception when trying to build a project that was mounted as read-only filesystem in a VM. The project set its own gradle cache so changing GRADLE_USER_HOME did not work. I had to change the filesystem to be read/write.



回答10:

Restarting the machine solved the issue.



回答11:

For me this was to do with Java versions. I have Java 10 installed and as the default Java on my system. Setting a JAVA_HOME pointing at Java 8 was sufficient for the project (graphql-spring-boot) to build.



标签: gradle