Skip to content

Commit c9d3885

Browse files
authored
SOLR-17406: Introduce Version Catalogs (#2706)
Introduce project-wide Gradle versions catalogs. Read the updated docs for more information. Breaking Changes: Any dependencies added from now on are no longer added to versions.props (file removed), but to gradle/libs.versions.toml. When referencing a dependency in a gradle module, use the version catalog instead of hardcoded strings. Dependencies are now locked with gradlew writeLocks (subject to change).
1 parent 24fe191 commit c9d3885

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+21820
-1364
lines changed

build-tools/build-infra/build.gradle

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
plugins {
1919
id "java-gradle-plugin"
20-
id 'com.diffplug.spotless' version '6.5.2' apply false
20+
alias(libs.plugins.diffplug.spotless) apply false
2121
}
2222

2323
repositories {
@@ -34,12 +34,9 @@ apply from: file('../../gradle/validation/check-environment.gradle')
3434
tasks.register("checkJdkInternalsExportedToGradle") {}
3535
apply from: file('../../gradle/validation/spotless.gradle')
3636

37-
// Load common script dependencies.
38-
apply from: file("../scriptDepVersions.gradle")
39-
4037
java {
41-
sourceCompatibility = scriptDepVersions['min-java-version']
42-
targetCompatibility = scriptDepVersions['min-java-version']
38+
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.min.get())
39+
targetCompatibility = JavaVersion.toVersion(libs.versions.java.min.get())
4340
}
4441

4542
gradlePlugin {
@@ -57,5 +54,5 @@ dependencies {
5754
implementation gradleApi()
5855
implementation localGroovy()
5956

60-
implementation "commons-codec:commons-codec:${scriptDepVersions['commons-codec']}"
57+
implementation libs.commonscodec.commonscodec
6158
}

build-tools/build-infra/settings.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
*/
1717

1818
rootProject.name = 'build-infra'
19+
20+
// Use project's version catalog for centralized dependency management
21+
dependencyResolutionManagement {
22+
versionCatalogs {
23+
libs {
24+
from(files("../../gradle/libs.versions.toml"))
25+
}
26+
}
27+
}

build-tools/missing-doclet/build.gradle

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
plugins {
1919
id 'java-library'
20-
id 'com.diffplug.spotless' version '6.5.2' apply false
20+
alias(libs.plugins.diffplug.spotless) apply false
2121
}
2222

2323
repositories {
2424
mavenCentral()
2525
}
2626

27-
version = "1.0.0-SNAPSHOT"
2827
group = "org.apache.solr.tools"
2928
description = 'Doclet-based javadoc validation'
3029

@@ -36,12 +35,9 @@ apply from: file('../../gradle/validation/check-environment.gradle')
3635
tasks.register("checkJdkInternalsExportedToGradle") {}
3736
apply from: file('../../gradle/validation/spotless.gradle')
3837

39-
// Load common script dependencies.
40-
apply from: file("../scriptDepVersions.gradle")
41-
4238
java {
43-
sourceCompatibility = scriptDepVersions['min-java-version']
44-
targetCompatibility = scriptDepVersions['min-java-version']
39+
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.min.get())
40+
targetCompatibility = JavaVersion.toVersion(libs.versions.java.min.get())
4541
}
4642

4743
tasks.withType(JavaCompile).configureEach {

build-tools/missing-doclet/settings.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
*/
1717

1818
rootProject.name = "missing-doclet"
19+
20+
// Use project's version catalog for centralized dependency management
21+
dependencyResolutionManagement {
22+
versionCatalogs {
23+
libs {
24+
from(files("../../gradle/libs.versions.toml"))
25+
}
26+
}
27+
}

build-tools/scriptDepVersions.gradle

-33
This file was deleted.

build.gradle

+16-15
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ import java.time.format.DateTimeFormatter
2121
plugins {
2222
id 'base'
2323
id 'solr.build-infra'
24-
id 'com.palantir.consistent-versions' version '2.16.0'
25-
id 'org.owasp.dependencycheck' version '9.0.8'
26-
id 'ca.cutterslade.analyze' version '1.10.0'
27-
id 'de.thetaphi.forbiddenapis' version '3.7' apply false
28-
id 'de.undercouch.download' version '5.5.0' apply false
29-
id 'net.ltgt.errorprone' version '3.1.0' apply false
30-
id 'com.diffplug.spotless' version '6.5.2' apply false
31-
id 'com.github.node-gradle.node' version '7.0.1' apply false
32-
}
3324

34-
apply from: file('build-tools/scriptDepVersions.gradle')
25+
alias(libs.plugins.carrotsearch.dependencychecks)
26+
alias(libs.plugins.owasp.dependencycheck)
27+
alias(libs.plugins.cutterslade.analyze)
28+
alias(libs.plugins.benmanes.versions)
29+
alias(libs.plugins.littlerobots.versioncatalogupdate) apply false
30+
alias(libs.plugins.thetaphi.forbiddenapis) apply false
31+
alias(libs.plugins.undercouch.download) apply false
32+
alias(libs.plugins.ltgt.errorprone) apply false
33+
alias(libs.plugins.diffplug.spotless) apply false
34+
alias(libs.plugins.nodegradle.node) apply false
35+
alias(libs.plugins.openapi.generator) apply false
36+
}
3537

3638
// Declare default Java versions for the entire project and for SolrJ separately
37-
rootProject.ext.minJavaVersionDefault = JavaVersion.toVersion(scriptDepVersions['min-java-version'])
38-
rootProject.ext.minJavaVersionSolrJ = JavaVersion.toVersion(scriptDepVersions['min-solrj-java-version'])
39+
rootProject.ext.minJavaVersionDefault = JavaVersion.toVersion(libs.versions.java.min.get())
40+
rootProject.ext.minJavaVersionSolrJ = JavaVersion.toVersion(libs.versions.java.solrj.get())
3941

4042
apply from: file('gradle/globals.gradle')
4143

@@ -100,7 +102,7 @@ ext {
100102
}
101103

102104
luceneBaseVersionProvider = project.provider {
103-
def luceneVersion = getVersion('org.apache.lucene:lucene-core')
105+
def luceneVersion = libs.versions.apache.lucene.get()
104106
def m = (luceneVersion =~ /^\d+\.\d+\.\d+\b/)
105107
if (!m) {
106108
throw GradleException("Can't strip base version from " + luceneVersion)
@@ -150,7 +152,6 @@ apply from: file('gradle/validation/precommit.gradle')
150152
apply from: file('gradle/validation/forbidden-apis.gradle')
151153
apply from: file('gradle/validation/jar-checks.gradle')
152154
apply from: file('gradle/validation/git-status.gradle')
153-
apply from: file('gradle/validation/versions-props-sorted.gradle')
154155
apply from: file('gradle/validation/validate-source-patterns.gradle')
155156
apply from: file('gradle/validation/rat-sources.gradle')
156157
apply from: file('gradle/validation/owasp-dependency-check.gradle')
@@ -161,7 +162,7 @@ apply from: file('gradle/validation/validate-log-calls.gradle')
161162
apply from: file('gradle/validation/check-broken-links.gradle')
162163

163164
apply from: file('gradle/validation/solr.config-file-sanity.gradle')
164-
165+
apply from: file('gradle/validation/dependencies.gradle')
165166
apply from: file('gradle/validation/spotless.gradle')
166167

167168
// Wire up included builds to some validation tasks.

dev-docs/dependency-upgrades.adoc

+35-8
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,57 @@
1616
// specific language governing permissions and limitations
1717
// under the License.
1818

19-
Solr has lots of 3rd party dependencies, defined mainly in `versions.props`.
19+
Solr has lots of 3rd party dependencies, defined in `gradle/libs.versions.toml`.
2020
Keeping them up-to-date is crucial for a number of reasons:
2121

2222
* minimizing the risk of critical CVE vulnerabilities by staying on a recent and supported version
2323
* avoiding "dependency hell", that can arise from falling too far behind
2424
25-
Read the https://github.com/apache/solr/blob/main/help/dependencies.txt[help/dependencies.txt] file for an in-depth explanation of how gradle is deployed in Solr, using
26-
https://github.com/palantir/gradle-consistent-versions[Gradle consistent-versions] plugin.
25+
Read the https://github.com/apache/solr/blob/main/help/dependencies.txt[help/dependencies.txt] file for an in-depth
26+
explanation of how dependencies are managed.
2727

2828
== Manual dependency upgrades
2929
In order to upgrade a dependency, you need to run through a number of steps:
3030

3131
1. Identify the available versions from e.g. https://search.maven.org[Maven Central]
32-
2. Update the version in `versions.props` file
33-
3. Run `./gradlew --write-locks` to re-generate `versions.lock`. Note that this may cause a cascading effect where
32+
2. Update the version in `gradle/libs.versions.toml` file
33+
3. Run `./gradlew writeLocks` to re-generate `versions.lock`. Note that this may cause a cascading effect where
3434
the locked version of other dependencies also change.
35-
4. Run `./gradlew updateLicenses` to re-generate SHA1 checksums of the new jar files.
36-
5. Once in a while, a new version of a dependency will transitively bring in brand-new dependencies.
35+
4. In case of a conflict, resolve the conflict according to `help/dependencies.txt`
36+
5. Check if there are any constraints that are obsolete after the dependency update
37+
6. Update the license and notice files of the changed dependencies. See `help/dependencies.txt` for
38+
details.
39+
7. Run `./gradlew updateLicenses` to re-generate SHA1 checksums of the new jar files.
40+
8. Once in a while, a new version of a dependency will transitively bring in brand-new dependencies.
3741
You'll need to decide whether to keep or exclude them. See `help/dependencies.txt` for details.
3842

43+
=== Reviewing Constraints
44+
45+
The constraints are defined in gradle/validation/dependencies.gradle. There, if the updated dependency is listed,
46+
the constraint can be reviewed, updated or removed.
47+
48+
The constraints fall into two "groups". In the first group there are dependency constraints from dependencies
49+
that our project directly includes and require version alignment to sync the versions across all transitive
50+
dependencies. In the second group are dependencies that are only present as transitive dependencies.
51+
There, we try to follow the convention to provide additional information with "which dependencies use what version",
52+
so that the next person reviewing the constraint does not have to look it up. However, this is quite time-consuming
53+
to analyze the dependencies and therefore subject to change.
54+
55+
In order to review a constraint, you have to check if the updated dependency is mentioned in any of the constraints,
56+
either as a reason for another dependency constraint or as the constraint's dependency. Removing temporarily
57+
a constraint, the task writeLocks will fail if the constraint is still required.
58+
59+
This process and the constraints of dependencies.gradle are not optimal, as it is quite time-consuming and not obvious
60+
by just looking at it. We just haven't found yet a more efficient way to maintain these constraints.
61+
3962
== Renovate bot Pull Requests
63+
64+
The renovate bot may be replaced in the future with dependabot and this section may only be relevant for older
65+
versions (<10.0). See https://lists.apache.org/thread/1sb9ttv3lp57z2yod1htx1fykp5sj73z for updates.
66+
4067
A member of the Solr community operates a Github bot running https://github.com/renovatebot/renovate[Renovate], which
4168
files Pull Requests to Solr with dependency upgrade proposals. The PRs are labeled `dependencies` and do include
42-
changes resulting from `gradle --write-locks` and `updateLicenses`.
69+
changes resulting from `./gradlew writeLocks` and `updateLicenses`.
4370

4471
Community members and committers can then review, and if manual changes are needed, help bring the PR to completion.
4572
For many dependencies, a changelog is included in the PR text, which may help guide the upgrade decision.

gradle/documentation/markdown.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ buildscript {
3333
}
3434

3535
dependencies {
36-
classpath "com.vladsch.flexmark:flexmark:${scriptDepVersions['flexmark']}"
37-
classpath "com.vladsch.flexmark:flexmark-ext-abbreviation:${scriptDepVersions['flexmark']}"
38-
classpath "com.vladsch.flexmark:flexmark-ext-attributes:${scriptDepVersions['flexmark']}"
39-
classpath "com.vladsch.flexmark:flexmark-ext-autolink:${scriptDepVersions['flexmark']}"
36+
classpath libs.flexmark.flexmark
37+
classpath libs.flexmark.extensions.abbreviation
38+
classpath libs.flexmark.extensions.attributes
39+
classpath libs.flexmark.extensions.autolink
4040
}
4141
}
4242

gradle/documentation/pull-lucene-javadocs.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ configure(project(":solr:documentation")) {
4545
// from all Solr javadocs?) then perhaps we can find a way to build this list programatically?
4646
// - If these javadocs are (only every) consumed by the ref guide only, then these deps & associated tasks
4747
// should just be moved to the ref-guide build.gradle
48-
javadocs group: 'org.apache.lucene', name: 'lucene-core', classifier: 'javadoc'
49-
javadocs group: 'org.apache.lucene', name: 'lucene-analysis-common', classifier: 'javadoc'
50-
javadocs group: 'org.apache.lucene', name: 'lucene-analysis-stempel', classifier: 'javadoc'
51-
javadocs group: 'org.apache.lucene', name: 'lucene-queryparser', classifier: 'javadoc'
52-
javadocs group: 'org.apache.lucene', name: 'lucene-spatial-extras', classifier: 'javadoc'
48+
javadocs variantOf(libs.apache.lucene.core) { classifier 'javadoc' }
49+
javadocs variantOf(libs.apache.lucene.analysis.common) { classifier 'javadoc' }
50+
javadocs variantOf(libs.apache.lucene.analysis.stempel) { classifier 'javadoc' }
51+
javadocs variantOf(libs.apache.lucene.queryparser) { classifier 'javadoc' }
52+
javadocs variantOf(libs.apache.lucene.spatialextras) { classifier 'javadoc' }
5353
}
5454

5555

gradle/generation/javacc.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ configure(rootProject) {
2626
}
2727

2828
dependencies {
29-
javacc "net.java.dev.javacc:javacc:${scriptDepVersions['javacc']}"
29+
javacc libs.javacc.javacc
3030
}
3131

3232
task javacc() {

0 commit comments

Comments
 (0)