-
Notifications
You must be signed in to change notification settings - Fork 5k
Introduce a settings DSL for central dependency declaration #14896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
60b13a1
to
a4f434a
Compare
That is awesome.
Do you think it could support overriding the version with a command-line flag? What is the approach for file splitting? |
Technically speaking we can. Now I'd have to talk to the larger team to say if we should :) Note that if you override a dependency version, it would probably only override the default model, so if you have something like:
For now I'd say KISS. We could provide alternatives if there's a legitimate interest in making this more complicated. Alternatively settings plugins can provide this feature. Last but not least, because we do code generation we could hit the limit of the number of methods in a class...
This PR lets you declare this:
then you don't have to specify a version when applying in build scripts. |
Let me clarify the use-case. I want to verify if my project works with a newer version of a third-party dependency. Note: I can't use
Here's the case where I install Here's the case when Checkstyle CI job verifies the new Checkstyle works for verifying of pgjdbc sources: https://github.com/checkstyle/checkstyle/blob/3c2249b239cbfe002af3649f1f7c1f9ae61df3b1/.ci/wercker.sh#L60-L71 |
I wonder if TOML could be separate from the code generator, so out-of-core plugins could leverage the same generator. |
That's exactly the case: the TOML file is just, if you will, a standard plugin hooking into the code generator. In the end, there's a single code generator and settings plugins can contribute entries. But in the end we're going to be limited by the number of methods which can be defined in a class file. |
That is certainly a legitimate use case. |
That looks seriously awesome 🤩 . Thanks for addressing this !! Will the TOML file support dependencies "groups" that need to be all the same version so that it can be changed in a single place? For an example (that obviously won't work since I don't think TOML supports variables) but just to demonstrate the goal: [versions]
sqldelight = "1.7.0"
[dependencies]
sqlDelightPlugin = { group = "com.squareup.sqldelight", name = "gradle-plugin", version = "${versions.sqldelight}" }
sqlDelightDriverAndroid = { group = "com.squareup.sqldelight", name = "android-driver", version.strictly = "${versions.sqldelight}" }
sqlDelightDriverAndroid = { group = "com.squareup.sqldelight", name = "native-driver", version.strictly = "${versions.sqldelight}" }
Also would it be possible to copy/paste the maven coordinates in one go? That's a minor change but not having to separate group/artifactId/version would be a nice addition as most of the documentations use that representation: [dependencies]
guava = { gav = "com.google.guava:guava:27.0-jre" } Which leads me to a wider question: did you consider a Kotlin script for this that would expose a strongly typed way to register dependencies and could be self documented? Something like dependencies {
create("guava") {
group = "com.google.guava"
artifact = "guava"
version= "27.0-jre"
}
// or the shorthand gav version
create("guava") {
gav = "com.google.guava:guava:27.0-jre"
}
}
bundles {
create("groovy") {
from("groovy", "groovy-json")
}
} Could that work? |
Not out of the box. If we do this I'd rather add a
That's already supported by this PR :)
There's already the settings DSL for this. Note, however, that using Kotlin or the settings DSL would invalidate all build scripts classpath and trigger recompilation of all scripts if any version or coordinate changes, whereas using the TOML this would only happen if you add/remove an alias, not if you change GAV coordinates. |
This commit introduces a new DSL, available on
Settings
via thedependency resolution management block, which allows declaring aliases
for dependencies and bundles of dependencies.
Doing this, Gradle will automatically generate type-safe accessors
which are exposed as extensions to all projects. This effectively
allows sharing dependency declarations between projects.
Said differently, this is an officially supported pattern for the
various "dependency version sharing" patterns that we found in the
wild:
the version via
project.someLibraryVersion
buildSrc
which contains dependency coordinatesand then can be accessed in the different projects
In addition to this DSL, we introduce a TOML file, which, if found under
the
gradle
directory, will be used to source dependency aliases.For example, giving the following file:
a dependency can be added in a project using the type-safe
libs
extension:This file also supports bundles of dependencies, in case more than one
dependency needs to be added:
then dependencies can be added via:
The file is configuration-cache safe: any change to the file will invalidate the
cache. But more importantly, it's build cache safe: if the aliases don't change,
there's no need to rebuild the dependent scripts. This means that changing this
file by changing, for example, the dependency versions, will not trigger a
recompilation of build scripts like some of the approaches described above.
The TOML file also lets you declare plugin versions:
which allows application of the plugin without version in build scripts:
In addition, we also generate type-safe accessors for projects. For example:
can be replaced with:
Therefore any change to project coordinates, or removals of subprojects would
trigger a build script compilation error, avoiding tedious search and replace.
Fixes #?
Context
Contributor Checklist
<subproject>/src/integTest
) to verify changes from a user perspective<subproject>/src/test
) to verify logic./gradlew <changed-subproject>:check
Gradle Core Team Checklist