1

I'm currently in the progress of upgrading a Spring Boot Gradle project from 2.7.x to 3.0.x. In this project we've declarated the Ehcache library as a API dependency:

api 'org.ehcache:ehcache'

After reading the migration guide, I've changed this to the following:

api('org.ehcache:ehcache') {
    capabilities {
        requireCapability('org.ehcache:ehcache-jakarta')
    }
}

However after running ./gradlew build, Gradle failed to resolve the dependency:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find org.ehcache:ehcache:.
     Required by:
         project :

I've tried the following possible workarounds:

api 'org.ehcache:ehcache-jakarta'

Does not work.

api 'org.ehcache:ehcache:jakarta'

Does not work.

However, when declaring a version it does work:

api 'org.ehcache:ehcache:3.10.8:jakarta'

But why declare a version if this is managed by Spring Boot?

Spring Boot version: 3.0.4 Gradle Wrapper version: 7.6.1

Maarten1985
  • 123
  • 6

2 Answers2

3

You can configure a dependency with a classifier and without a version like this:

api("org.ehcache:ehcache::jakarta")

Note the :: that omits the version.

For Spring Boot's dependency management to apply correctly in this instance, you'll have to use Gradle's built-in platform support rather than the dependency management plugin:

api(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • It works in my sample project. However in our large multi-module project, which is still setup the old way (with buildscript), the `publishToMavenLocal` task fails. `org.codehaus.plexus.util.xml.pull.XmlPullParserException: Duplicated tag: 'dependencyManagement' (position: START_TAG seen ...\n ... @148:25)` – Maarten1985 May 03 '23 at 09:40
  • Are you using both the dependency management plugin and Gradle's platform support in the same project? If so, you are hitting https://github.com/gradle/gradle/issues/21277. I'd recommend only using one or the other. – Andy Wilkinson May 03 '23 at 11:00
0

Here is another workaround.

implementation "org.ehcache:ehcache:${dependencyManagement.importedProperties['ehcache3.version']}:jakarta"

https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#accessing-properties