caffeine: Problem when adding Caffeine to a Tar in Gradle

Gradle Version: 6.3 Java Version: 11.0.11 (Amazon.com Inc. 11.0.11+9-LTS) Caffeine Version: 3.0.3

This is probably a configuration problem on my part, but I’m not sure where else to ask about it.

I have a gradle sub-project that gets caffeine as a transitive dependency (from jdbi). It builds without issue. However, I have a separate gradle sub-project that pulls the first artifact and its dependencies into a tar using the distribution plugin, using the following configuration:

configurations {
    library
}

dependencies {
    library(project(':my-project:project-jar'))
}

distributions {
    main {
        contents {
            into('/lib') {
                from configurations.library.files
            }
        }
    }
}

When the caffeine version is 3.x and I run the distTar task for this configuration, I get the following error:

Could not resolve com.github.ben-manes.caffeine:caffeine:3.0.3.
      Required by:
          project :my-project:project-tar > project :my-project:project-jar > org.jdbi:jdbi3-core:3.29.0
       > Cannot choose between the following variants of com.github.ben-manes.caffeine:caffeine:3.0.3:
           - runtimeElements
           - shadowRuntimeElements

If I bring the dependency down to the point where the Caffeine dependency resolves to 2.x, this issue goes away.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (14 by maintainers)

Commits related to this issue

Most upvoted comments

finally works as below:

 configurations { 
  . . . . . . 
  . . . . . . 
  caffeine
  . . . . . . 
  . . . . . . 
 }

 dependencies {
  . . . . . . 
  . . . . . . 
  caffeine ('com.github.ben-manes.caffeine:caffeine:2.9.3')  {
         attributes {
            attribute(Attribute.of("org.gradle.dependency.bundling", String), "external")
         }	 
  }
  . . . . . . 
  . . . . . . 
 }

since all I can do is guess, what about using an attribute to force the selection?

dependencies {
  implementation('com.github.ben-manes.caffeine:caffeine:2.9.3') {
    attributes {
      attribute(Attribute.of("org.gradle.dependency.bundling", String), "external")
    }
  }
}