Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle :Could not create service of type FileHasher

Tags:

gradle

I'm using Gradle to build a java project. When I run any task (assemble, test). I get randomly an error :

Could not create service of type FileHasher using 
GradleUserHomeScopeServices.createCachingFileHasher()

Did any one had the same issue before?

Gradle V:3.5

java 8

I'm using the java plugin.

Thanks,

like image 750
Anas K Avatar asked Jul 18 '17 22:07

Anas K


3 Answers

I was facing the same because I accidentally hit ctrl+z during build, and then the error was the same as yours.

I tried to remove the lock file but it didn't solve the problem.

Then I find all the process related to gradle by ps aux | grep gradle, and then kill -9 <pid> them all. The build backed to normal.

like image 189
Leighton Avatar answered Nov 09 '22 04:11

Leighton


In your terminal type this:

./gradlew build

and the outcome would be:

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type FileHasher using GradleUserHomeScopeServices.createCachingFileHasher().
> Timeout waiting to lock file hash cache (/Users/zra/.gradle/caches/4.1-rc-1/fileHashes). It is currently in use by another Gradle instance.
  Owner PID: 17571
  Our PID: 26055
  Owner Operation: 
  Our operation: 
  Lock file: /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock

now do:

rm /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock

and build again.

P.S replace xxx with whatever username you've.

like image 33
Zahid Rasheed Avatar answered Nov 09 '22 03:11

Zahid Rasheed


What worked for me was removing the lock file like suggested in the answer above: rm /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock and also killing the IDLE processes by running the command

./gradlew --status

It generates a list of gradle processes with status like

  PID STATUS   INFO
 23580 IDLE     5.2.1
 23860 IDLE     5.2.1
 19058 STOPPED  (stop command received)

Then kill one of the idle processes by kill <PID> and run the gradle build again.

like image 22
ZuckerWatte Avatar answered Nov 09 '22 04:11

ZuckerWatte