Skip to content

Commit 95eaed2

Browse files
committed
buildSrc: checkForUpdates comments to tune version search
This will make it more likely that we notice minor and patch releases for dependencies that we can't update to the brand newest while also reducing the checkForUpdate noise/toil.
1 parent 725ab22 commit 95eaed2

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,5 +533,5 @@ configurations {
533533
}
534534
}
535535

536-
tasks.register('checkForUpdates', CheckForUpdatesTask, project.configurations.checkForUpdates, "libs")
536+
tasks.register('checkForUpdates', CheckForUpdatesTask, project.configurations.checkForUpdates, "libs", layout.projectDirectory.file("gradle/libs.versions.toml"))
537537

buildSrc/src/main/java/io/grpc/gradle/CheckForUpdatesTask.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616

1717
package io.grpc.gradle;
1818

19+
import java.io.IOException;
20+
import java.nio.file.Files;
1921
import java.util.Collections;
2022
import java.util.HashMap;
2123
import java.util.LinkedHashSet;
24+
import java.util.List;
2225
import java.util.Map;
2326
import java.util.Set;
27+
import java.util.stream.Collectors;
2428
import javax.inject.Inject;
2529
import org.gradle.api.DefaultTask;
2630
import org.gradle.api.artifacts.Configuration;
@@ -32,6 +36,7 @@
3236
import org.gradle.api.artifacts.result.ResolvedComponentResult;
3337
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
3438
import org.gradle.api.artifacts.result.UnresolvedDependencyResult;
39+
import org.gradle.api.file.RegularFile;
3540
import org.gradle.api.provider.Provider;
3641
import org.gradle.api.tasks.Input;
3742
import org.gradle.api.tasks.Nested;
@@ -45,7 +50,23 @@ public abstract class CheckForUpdatesTask extends DefaultTask {
4550
private final Set<Library> libraries;
4651

4752
@Inject
48-
public CheckForUpdatesTask(Configuration updateConf, String catalog) {
53+
public CheckForUpdatesTask(Configuration updateConf, String catalog, RegularFile commentFile)
54+
throws IOException {
55+
// Check for overrides to the default version selection ('+'), using comments of the form:
56+
// # checkForUpdates: library-name:1.2.+
57+
List<String> fileComments = Files.lines(commentFile.getAsFile().toPath())
58+
.filter(l -> l.matches("# *checkForUpdates:.*"))
59+
.map(l -> l.replaceFirst("# *checkForUpdates:", "").strip())
60+
.collect(Collectors.toList());
61+
Map<String, String> aliasToVersionSelector = new HashMap<>(2*fileComments.size());
62+
for (String comment : fileComments) {
63+
String[] parts = comment.split(":", 2);
64+
String name = parts[0].replaceAll("[_-]", ".");
65+
if (aliasToVersionSelector.put(name, parts[1]) != null) {
66+
throw new RuntimeException("Duplicate checkForUpdates comment for library: " + name);
67+
}
68+
}
69+
4970
updateConf.setVisible(false);
5071
updateConf.setTransitive(false);
5172
VersionCatalog versionCatalog = getProject().getExtensions().getByType(VersionCatalogsExtension.class).named(catalog);
@@ -59,15 +80,23 @@ public CheckForUpdatesTask(Configuration updateConf, String catalog) {
5980
oldConf.getDependencies().add(oldDep);
6081

6182
Configuration newConf = updateConf.copy();
83+
String versionSelector = aliasToVersionSelector.remove(name);
84+
if (versionSelector == null) {
85+
versionSelector = "+";
86+
}
6287
Dependency newDep = getProject().getDependencies().create(
63-
depMap(dep.getGroup(), dep.getName(), "+", "pom"));
88+
depMap(dep.getGroup(), dep.getName(), versionSelector, "pom"));
6489
newConf.getDependencies().add(newDep);
6590

6691
libraries.add(new Library(
6792
name,
6893
oldConf.getIncoming().getResolutionResult().getRootComponent(),
6994
newConf.getIncoming().getResolutionResult().getRootComponent()));
7095
}
96+
if (!aliasToVersionSelector.isEmpty()) {
97+
throw new RuntimeException(
98+
"Unused checkForUpdates comments: " + aliasToVersionSelector.keySet());
99+
}
71100
this.libraries = Collections.unmodifiableSet(libraries);
72101
}
73102

@@ -96,10 +125,16 @@ public void checkForUpdates() {
96125
"- Current version of libs.%s not resolved", name));
97126
continue;
98127
}
128+
DependencyResult newResult = lib.getNewResult().get().getDependencies().iterator().next();
129+
if (newResult instanceof UnresolvedDependencyResult) {
130+
System.out.println(String.format(
131+
"- New version of libs.%s not resolved", name));
132+
continue;
133+
}
99134
ModuleVersionIdentifier oldId =
100135
((ResolvedDependencyResult) oldResult).getSelected().getModuleVersion();
101-
ModuleVersionIdentifier newId = ((ResolvedDependencyResult) lib.getNewResult().get()
102-
.getDependencies().iterator().next()).getSelected().getModuleVersion();
136+
ModuleVersionIdentifier newId =
137+
((ResolvedDependencyResult) newResult).getSelected().getModuleVersion();
103138
if (oldId != newId) {
104139
System.out.println(String.format(
105140
"libs.%s = %s %s -> %s",

gradle/libs.versions.toml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ protobuf = "3.25.8"
1111
[libraries]
1212
android-annotations = "com.google.android:annotations:4.1.1.4"
1313
# androidx-annotation 1.9.1+ uses Kotlin and requires Android Gradle Plugin 9+
14+
# checkForUpdates: androidx-annotation:1.9.0
1415
androidx-annotation = "androidx.annotation:annotation:1.9.0"
1516
# 1.15.0 requires libraries and applications that depend on it to compile against
1617
# version 35 or later of the Android APIs.
18+
# checkForUpdates: androidx-core:1.13.+
1719
androidx-core = "androidx.core:core:1.13.1"
1820
# androidx-lifecycle 2.9+ requires Java 17
1921
androidx-lifecycle-common = "androidx.lifecycle:lifecycle-common:2.8.7"
@@ -33,15 +35,19 @@ cronet-api = "org.chromium.net:cronet-api:119.6045.31"
3335
cronet-embedded = "org.chromium.net:cronet-embedded:119.6045.31"
3436
errorprone-annotations = "com.google.errorprone:error_prone_annotations:2.36.0"
3537
# error-prone 2.32.0+ require Java 17+
38+
# checkForUpdates: errorprone-core:2.31.+
3639
errorprone-core = "com.google.errorprone:error_prone_core:2.31.0"
3740
google-api-protos = "com.google.api.grpc:proto-google-common-protos:2.59.2"
3841
# google-auth-library 1.25.0+ requires error_prone_annotations 2.31.0+, which
3942
# breaks the Android build
43+
# checkForUpdates: google-auth-credentials:1.24.+
4044
google-auth-credentials = "com.google.auth:google-auth-library-credentials:1.24.1"
45+
# checkForUpdates: google-auth-oauth2Http:1.24.+
4146
google-auth-oauth2Http = "com.google.auth:google-auth-library-oauth2-http:1.24.1"
4247
# Release notes: https://cloud.google.com/logging/docs/release-notes
4348
google-cloud-logging = "com.google.cloud:google-cloud-logging:3.23.1"
4449
# 2.13.0 requires error_prone_annotations:2.37.0, but we are stuck with 2.36.0
50+
# checkForUpdates: gson:2.12.+
4551
gson = "com.google.code.gson:gson:2.12.1"
4652
# 33.4.8 requires com.google.errorprone:error_prone_annotations:2.36.0
4753
guava = "com.google.guava:guava:33.4.8-android"
@@ -52,9 +58,11 @@ guava-testlib = "com.google.guava:guava-testlib:33.4.8-android"
5258
guava-jre = "com.google.guava:guava:33.4.8-jre"
5359
hdrhistogram = "org.hdrhistogram:HdrHistogram:2.2.2"
5460
# 6.0.0+ use java.lang.Deprecated forRemoval and since from Java 9
61+
# checkForUpdates: jakarta-servlet-api:5.+
5562
jakarta-servlet-api = "jakarta.servlet:jakarta.servlet-api:5.0.0"
5663
javax-servlet-api = "javax.servlet:javax.servlet-api:4.0.1"
5764
# 12.0.0+ require Java 17+
65+
# checkForUpdates: jetty-client:11.+
5866
jetty-client = "org.eclipse.jetty:jetty-client:11.0.24"
5967
jetty-http2-server = "org.eclipse.jetty.http2:jetty-http2-server:12.0.23"
6068
jetty-http2-server10 = "org.eclipse.jetty.http2:http2-server:10.0.20"
@@ -79,6 +87,7 @@ netty-transport-epoll = { module = "io.netty:netty-transport-native-epoll", vers
7987
netty-unix-common = { module = "io.netty:netty-transport-native-unix-common", version.ref = "netty" }
8088
okhttp = "com.squareup.okhttp:okhttp:2.7.5"
8189
# okio 3.5+ uses Kotlin 1.9+ which requires Android Gradle Plugin 9+
90+
# checkForUpdates: okio:3.4.+
8291
okio = "com.squareup.okio:okio:3.4.0"
8392
opencensus-api = { module = "io.opencensus:opencensus-api", version.ref = "opencensus" }
8493
opencensus-contrib-grpc-metrics = { module = "io.opencensus:opencensus-contrib-grpc-metrics", version.ref = "opencensus" }
@@ -101,14 +110,19 @@ s2a-proto = "com.google.s2a.proto.v2:s2a-proto:0.1.2"
101110
signature-android = "net.sf.androidscents.signature:android-api-level-21:5.0.1_r2"
102111
signature-java = "org.codehaus.mojo.signature:java18:1.0"
103112
# 11.0.0+ require Java 17+
113+
# checkForUpdates: tomcat-embed-core:10.+
104114
tomcat-embed-core = "org.apache.tomcat.embed:tomcat-embed-core:10.1.31"
115+
# checkForUpdates: tomcat-embed-core9:9.+
105116
tomcat-embed-core9 = "org.apache.tomcat.embed:tomcat-embed-core:9.0.89"
106117
truth = "com.google.truth:truth:1.4.4"
118+
# checkForUpdates: undertow-servlet22:2.2.+
107119
undertow-servlet22 = "io.undertow:undertow-servlet:2.2.37.Final"
108120
undertow-servlet = "io.undertow:undertow-servlet:2.3.18.Final"
109121

110-
# Do not update: Pinned to the last version supporting Java 8.
111-
# See https://checkstyle.sourceforge.io/releasenotes.html#Release_10.1
122+
# checkstyle 10.0+ requires Java 11+
123+
# See https://checkstyle.sourceforge.io/releasenotes_old_8-35_10-26.html#Release_10.0
124+
# checkForUpdates: checkstylejava8:9.+
112125
checkstylejava8 = "com.puppycrawl.tools:checkstyle:9.3"
113126
# 2.11.0+ requires JDK 11+ (See https://github.com/google/error-prone/releases/tag/v2.11.0)
127+
# checkForUpdates: errorprone-corejava8:2.10.+
114128
errorprone-corejava8 = "com.google.errorprone:error_prone_core:2.10.0"

0 commit comments

Comments
 (0)