gradle clean fails with "GradleException: Failed to create Jar file"
Asked Answered
N

3

13

I'm seeing a very strange problem with gradle.

When I run any command (see clean below), gradle fails with a concurrent exception.

This is happening since my latest changes. Rolling back to a previous commit works fine.

The changes are too numerous to describe here but in summary I've restructured the build a bit, based on another project which is working. And when I say based on, I mean I have simply copied build.gradle, settings.gradle and gradle.properties from that other project. None of the changes relate to jackson core.

$ ./gradlew clean

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'myservice'.
> java.util.concurrent.ExecutionException: org.gradle.api.GradleException: Failed to create Jar file C:\Users\me\.gradle\caches\jars-9\b868ab677410c01cf9b5a0e29a035e73\jackson-core-2.15.2.jar.
    
BUILD FAILED in 2s

I tried removing the lock file but that failed:

$ rm -rf ~/.gradle/caches/jars-9/*lock
rm: cannot remove '/c/Users/me/.gradle/caches/jars-9/jars-9.lock': Device or resource busy

So I ran ./gradlew --stop which stopped 2 daemons, and I was able to remove the lock file. But the clean still fails with the same error.

I've tried cleaning the .gradle directory in the project, and I've also tried checking out a new copy of the project. Same result.

So although it seems like a cache error, I can fix it by rolling back to a previous commit (without touching the cache) and if I clear the cache, that doesn't fix it.

What's going wrong and how do I fix it?

Neolatin answered 3/10, 2023 at 20:34 Comment(2)
The error you're encountering appears to be related to a problem with the Gradle cache and the creation of a JAR file for the Jackson Core library. This kind of issue can sometimes occur due to file system conflicts or corruption in the Gradle cache. To resolve that issue: Clean Gradle Cache, Clear Gradle Caches, Update Gradle and Plugins, Check for Third-Party Dependencies.Neela
@AnisRafid I thought it might be the gradle cache. But I cleaned both the project-level cache and the user-level cache, and it still fails. When I switch to the previous commit, it works fine (even though it's using the same cache).Neolatin
N
23

The answer was to do with a bug in gradle. Versions prior to 7.6.2 (?) failed to handle multi-release jar files (ie with multiple binaries built with different Java versions in them).

The jackson dependency was such a jar file. This explains why the previous commit worked consistently, and this one failed consistently. The project from which I copied the config uses gradle 8.1, which is why it worked there.

Solution: upgrade gradle.

Neolatin answered 4/10, 2023 at 9:59 Comment(2)
This issue is finally resolved in version 8.4. So upgrade to 8.4 or higher.Recurve
7.6.4 seemed to work for me at least.Say
W
2

Error message

java.util.concurrent.ExecutionException: org.gradle.api.GradleException: Failed to create Jar file /Users/johnsmith/.gradle/caches/jars-9/b434e5cc9816519e3d9b77bd3c65f31a/jackson-core-2.16.0.jar

Upgrading to gradle 8.5 version using terminal solved my issue.

Wouldst answered 4/1 at 7:55 Comment(0)
H
0
Error: java.util.concurrent.ExecutionException: org.gradle.api.GradleException: 
Failed to create Jar file spring-core-6.0.10.jar.

Solution: Earlier, I am using gradle 7.2, updating to gradle 7.6 solved my issue.

Homophone answered 7/8 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.