-
Notifications
You must be signed in to change notification settings - Fork 21
Gradle and org.lz4:lz4‐java:1.8.1
To make the transition to the new group ID easier, Sonatype has published a relocation POM at org.lz4:lz4-java:1.8.1 that points to the new group ID, at.yawk.lz4:lz4-java:1.8.1. Depending on org.lz4:lz4-java:1.8.1 is equivalent to depending on the new group ID, and will also emit a warning to move to the new coordinate.
The artifacts under the at.yawk.lz4 group ID define gradle capabilities for org.lz4. That means that if you depend on both at.yawk.lz4 and org.lz4 in your project (maybe indirectly), gradle will detect a version conflict. This helps preventing an accidental transitive dependency on the old group ID.
Unfortunately, gradle has a bug where a dependency on the relocation pom at org.lz4:lz4-java:1.8.1 will lead to a conflict even when there is no at.yawk.lz4 dependency. For that reason, it is recommended to never depend on org.lz4:lz4-java:1.8.1, and always use the new group ID for that release.
Even if you're using maven to build your library, please depend on at.yawk.lz4:lz4-java:1.8.1 instead of org.lz4:lz4-java:1.8.1. If you do not, anyone using your library in a gradle project will experience the above error. Since org.lz4:lz4-java:1.8.1 is a relocation pom, the binary will be the same no matter what you define.
If you see this error:
% ./gradlew run
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.lz4:lz4-java:1.8.1.
Required by:
root project :
> Module 'org.lz4:lz4-java' has been rejected:
Cannot select module with conflict on capability 'org.lz4:lz4-java:1.8.1' also provided by [at.yawk.lz4:lz4-java:1.8.1(apiElements)]
> Could not resolve at.yawk.lz4:lz4-java:1.8.1.
Required by:
root project : > org.lz4:lz4-java:1.8.1
> Module 'at.yawk.lz4:lz4-java' has been rejected:
Cannot select module with conflict on capability 'org.lz4:lz4-java:1.8.1' also provided by [org.lz4:lz4-java:1.8.1(compile)]
and you cannot change the group ID of the dependency (e.g. because it comes from a transitive dependency), you can use the following snippet to resolve the conflict:
Kotlin (build.gradle.kts)
configurations.configureEach {
resolutionStrategy {
capabilitiesResolution {
withCapability("org.lz4:lz4-java") {
select(candidates.first { (it.id as ModuleComponentIdentifier).group == "at.yawk.lz4" })
}
}
}
}Groovy (build.gradle)
configurations.configureEach {
resolutionStrategy {
capabilitiesResolution {
withCapability("org.lz4:lz4-java") {
select(candidates.find { ((ModuleComponentIdentifier) it.id).group == "at.yawk.lz4" })
}
}
}
}(credits to @vampire)