Search code examples
spring-bootapache-commonsgradle-pluginspring-boot-gradle-pluginapache-commons-compress

bootJar task fails with Gradle 8.5 and Spring Boot 3.3.0, caused by Spring Boot Gradle plugin's usage of Apache commons compress library


I have the following setup:

Gradle: 8.5
Spring Boot 3.3.0
Kotlin: 1.9.23

Before I used Spring Boot 3.2.6, and after update to the latest version I encounter the following error when running bootJar task or any task depending on it:

Caused by: java.lang.NoSuchMethodError: 'void org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.putArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry)'
at org.springframework.boot.gradle.tasks.bundling.BootZipCopyAction$Processor.processDirectory(BootZipCopyAction.java:261)
at org.springframework.boot.gradle.tasks.bundling.BootZipCopyAction$Processor.process(BootZipCopyAction.java:241)

By checking the latest codebase of Spring Boot Gradle plugin, I was able to find the line mentioned in the stack trace. So the issue should be the wrong version of org.apache.commons.commons-compress library being used in the Spring Boot 3.3.0 Gradle plugin.

I see that I have different versions of org.apache.commons:commons-compress library present in the external dependencies of my project - 1.22, 1.24.0, and I believe one of those versions is used in Spring Boot plugin, where the aforementioned method is not available (I also use Testcontainers, so not sure which exact version corresponds to which dependency).

Unfortunately, I was unable to force the version 1.26.2 (latest at the moment) for the plugin, and I was also unable to find any similar question or issue raised regarding this.

I was hoping to find some answers to be able to upgrade to Spring Boot 3.3.0 successfully, and see if anyone else has encountered the issue and maybe has a workaround or even better a solution.


Solution

  • I had the same issue. In my case it was caused old version of commons-compress pulled as transitive dependency of testcontainers in buildSrc.

    That dependency was totally invisible until I put a breakpoint in BootZipCopyAction class (line 261) and run the Gradle task in IntelliJ with Debug Gradle scripts mode. Then looking at ZipArchiveOutputStream classloader (out.getClass().classLoader) revealed that it used classloader from :buildSrc - ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:]:buildSrc:}

    In my case I fixed the issue by adding implementation("org.apache.commons:commons-compress:1.26.2") to buildSrc/build.gradle.kts

    Sad is that running of gradle buildEnv shows still incorrect version of the dependency (it displays version 1.25.0 although it now uses 1.26.2)