Slackbot
03/16/2023, 2:10 PMmelix
03/16/2023, 2:29 PMjava {
consistentResolution {
useCompileClasspathVersions()
}
}
see https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/JavaResolutionConsistency.htmlVampire
03/16/2023, 2:32 PMtwisterrob
03/16/2023, 2:32 PMDaan
03/17/2023, 9:37 AMVampire
03/17/2023, 9:39 AMDaan
03/17/2023, 9:44 AMenforcedPlatform
should be fine right if you don't have anyone consuming the build? From https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import "This declaration is effectively transitive and so will apply to the dependency graph of your consumers."melix
03/17/2023, 9:45 AMmelix
03/17/2023, 9:45 AMenforcedPlatform
melix
03/17/2023, 9:45 AMDaan
03/17/2023, 9:46 AMVampire
03/17/2023, 9:46 AMtwisterrob
03/17/2023, 9:46 AMplatform()
, no need to enforce, I think @melix is only against enforcedPlatform()
, right?melix
03/17/2023, 9:47 AMforce
, which is also bad)melix
03/17/2023, 9:48 AMplatform()
, yes, but this wouldn't solve this consistency use case, unless the platform only uses strict dependencies.twisterrob
03/17/2023, 9:48 AMmelix
03/17/2023, 9:49 AMmelix
03/17/2023, 9:49 AMDaan
03/17/2023, 9:49 AMslf4j-api
resolved in different components of the build, I assumed to align the same version across the build would be to use enforcedPlatform()
. But based on the above it's better to use platform()
with strictly
?twisterrob
03/17/2023, 9:49 AMcompileOnly
and mismatching on testImplementation
because it was missing the dependency that wasn't provided by implementation
, but was transitively availablemelix
03/17/2023, 9:50 AMBut based on the above it's better to use platform() with strictly?Yes, it's better, but you can try without
strictly
first, if as @twisterrob said you use the latest, in general it would just work smoothly.twisterrob
03/17/2023, 9:51 AMmelix
03/17/2023, 9:51 AMmelix
03/17/2023, 9:51 AMtwisterrob
03/17/2023, 9:53 AMDaan
03/17/2023, 9:55 AMplatform()
and fail on version conflictstwisterrob
03/17/2023, 10:53 AMfailOnVersionConflict
to build successfully, do you have luck?
simple real example:
implementation("com.google.android.material:material:1.8.0")
// transitively pulls in androidx.drawerlayout:drawerlayout:1.1.1
implementation("androidx.appcompat:appcompat:1.6.1")
// transitively pulls in androidx.drawerlayout:drawerlayout:1.0.0
implementation(platform("..."))
// which contains constraint api("androidx.drawerlayout:drawerlayout:1.1.1")
results in
> Could not resolve all dependencies for configuration ':debugRuntimeClasspath'.
> Conflict(s) found for the following module(s):
- androidx.drawerlayout:drawerlayout between versions 1.1.1 and 1.0.0
Vampire
03/17/2023, 11:05 AMtwisterrob
03/17/2023, 11:06 AM:dependencies
output when things change.Daan
03/17/2023, 12:21 PMenforcedPlatform()
working.Daan
03/17/2023, 12:31 PMplatform()
, strictly
and failOnVersionConflict
seems to work 😄 Now trying to find out how to get the version reference from the version catalog, I'll leave the repo up as an exampleVampire
03/17/2023, 12:32 PMlibs.versions.foo
?twisterrob
03/17/2023, 12:34 PMlibs.foo.get().version
libs.foo.get().versionConstraint.requiredVersion
Daan
03/17/2023, 12:35 PMlibs.versions.jackson.get()
as strictly
only accepts a String
.twisterrob
03/17/2023, 12:35 PMstrictly
in the version catalog better?
https://github.com/gradle/gradle/issues/21544#issuecomment-1225234761twisterrob
03/17/2023, 12:37 PMconstraints { api(lib.foo) }
as well as implementation(lib.foo)
, don't we only want strictly
in the platform?Vampire
03/17/2023, 12:39 PMtwisterrob
03/17/2023, 12:39 PMVampire
03/17/2023, 12:40 PMlib.foo
and a lib.foo.strictly
if that is what you need.Daan
03/17/2023, 12:40 PMjackson = { strictly = "2.8.9" }
in the version catalog works 😄 Updated the repo accordinglytwisterrob
03/17/2023, 12:42 PMYou can also have arelated https://gradle-community.slack.com/archives/CAH4ZP3GX/p1679054200794169, the same approach could be used for thisand alib.foo
if that is what you need.lib.foo.strictly
Vampire
03/17/2023, 12:42 PMwhile with platform constraints I would imagine that only the resolution result ends up in the pomWhere constraints end up depends afair on whether you do them on
api
or implementation
like other dependencies.
The POM versions should afair not be influenced by the platform unless you configure to publish resolved versions which is an explicit setting.Vampire
03/17/2023, 12:43 PMUsingOrin the version catalog works 😄 Updated the repo accordinglyjackson = { strictly = "2.8.9" }
jackson = "2.8.9!!"
if you like the inline syntax moreDaan
03/17/2023, 12:44 PMstrictly
a bit more as its easier to google for other devs than !!
, thanks for the tip and all the helptwisterrob
03/17/2023, 12:45 PMDaan
03/17/2023, 12:46 PMVampire
03/17/2023, 12:47 PMapi
but on implementation
probablyDaan
03/17/2023, 12:51 PMdependencies {
constraints {
// 1. Configuration with name 'implementation' not found.
add('implementation', libs.jackson.core)
add('implementation', libs.jackson.databind)
// 2. > Could not find method implementation() for arguments [map(valueof(DependencyValueSource))] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyConstraintHandler.
implementation libs.jackson.core
implementation libs.jackson.databind
}
}
Vampire
03/17/2023, 12:55 PMapi
works at that spot? o_OVampire
03/17/2023, 12:55 PMVampire
03/17/2023, 12:56 PMDaan
03/17/2023, 12:56 PMapi
works 🤷 See the repo as exampleDaan
03/17/2023, 1:01 PMjava-platform
plugin only creates the api
configuration, not the implementation
one: https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaPlatformPlugin.java#L109.Vampire
03/17/2023, 1:06 PMtwisterrob
03/17/2023, 1:10 PMDaan
03/17/2023, 1:12 PMVampire
03/17/2023, 1:13 PMimplementation platform(project(':platform'))
vs. api platform(project(':platform'))
Daan
03/17/2023, 1:13 PMtwisterrob
03/17/2023, 1:14 PMDaan
03/17/2023, 1:14 PMimplementation
🙂Vampire
03/17/2023, 1:15 PMimplementation
it should not propagate to consumers.
But just double-check what happens. 🙂twisterrob
03/17/2023, 1:25 PMstrictly
only in platform:
api(constraintNotation) { version { strictly(version!!) } } // !! is Kotlin, not Gradle
Daan
03/17/2023, 1:26 PMDaan
03/17/2023, 1:26 PMtwisterrob
03/17/2023, 1:28 PM= "x!!"
-> does strictly everywhere (including dependencies, which can easily leak)
platform api { strictly(version!!)
-> strictly only in platform
so strictly(version!!)
is safer, but testing POM nowtwisterrob
03/17/2023, 2:02 PMstrictly
is the default in maven?! maybe I should be experimenting on a simpler project, because Android could be making things more interesting...twisterrob
03/17/2023, 2:06 PM<dependencyManagement>
<dependency>
<groupId>platform-group</groupId>
<artifactId>platform-name</artifactId>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
unless we do compileOnly(platform(...))
, so exactly the same as with deps.
compileOnly -> nothing
api -> as shown above
implementation -> as shown above
runtimeOnly -> as shown abovetwisterrob
03/17/2023, 2:11 PM<dependencies>
. I declared an outdated dependency, that has !!
and strictly(version!!)
, but in the POM, it shows up as the old version I declared in build.gradle directly. On :dependencies
the strictly
shows and all instances of the lib are -> strictVersion
.Vampire
03/17/2023, 2:36 PMVampire
03/17/2023, 2:37 PM