Skip to content

Commit 7a13a1d

Browse files
committed
WIP
1 parent d61367c commit 7a13a1d

File tree

10 files changed

+150
-17
lines changed

10 files changed

+150
-17
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,15 @@ dev_maven.install(
743743
"androidx.compose.foundation:foundation-layout:1.5.0-beta01",
744744
# https://github.com/bazel-contrib/rules_jvm_external/issues/909#issuecomment-2019217013
745745
"androidx.annotation:annotation:1.6.0",
746+
# Snapshot pinning support: https://github.com/bazel-contrib/rules_jvm_external/pull/1412
747+
"com.google.guava:guava:999.0.0-HEAD-jre-SNAPSHOT",
746748
],
747749
generate_compat_repositories = True,
748750
lock_file = "//tests/custom_maven_install:regression_testing_gradle_install.json",
749751
repositories = [
750752
"https://repo1.maven.org/maven2",
751753
"https://maven.google.com",
754+
"https://oss.sonatype.org/content/repositories/snapshots",
752755
],
753756
resolver = "gradle",
754757
)

private/rules/v2_lock_file.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ def _compute_lock_file_hash(lock_file_contents):
4848
return hash(repr(to_hash))
4949

5050
def _to_m2_path(unpacked):
51-
path = "{group}/{artifact}/{version}/{artifact}-{version}".format(
51+
path = "{group}/{artifact}/{version}/{artifact}-{version_revision}".format(
5252
artifact = unpacked["artifact"],
5353
group = unpacked["group"].replace(".", "/"),
5454
version = unpacked["version"],
55+
version_revision = unpacked.get("version_revision") or unpacked["version"]
5556
)
5657

5758
classifier = unpacked.get("classifier", "jar")
@@ -138,6 +139,7 @@ def _get_artifacts(lock_file_contents):
138139
"group": parts[0],
139140
"artifact": parts[1],
140141
"version": data["version"],
142+
"version_revision": data.get("version_revision"),
141143
}
142144
if len(parts) > 2:
143145
root_unpacked["packaging"] = parts[2]

private/tools/java/com/github/bazelbuild/rules_jvm_external/Coordinates.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class Coordinates implements Comparable<Coordinates> {
2424
private final String groupId;
2525
private final String artifactId;
2626
private final String version;
27+
private final String versionRevision;
2728
private final String classifier;
2829
private final String extension;
2930

@@ -59,16 +60,23 @@ public Coordinates(String coordinates) {
5960
classifier = "jar".equals(parts[3]) ? "" : parts[3];
6061
version = parts[4];
6162
}
63+
this.versionRevision = null;
6264
}
6365

6466
public Coordinates(
6567
String groupId, String artifactId, String extension, String classifier, String version) {
68+
this(groupId, artifactId, extension, classifier, version, null);
69+
}
70+
71+
public Coordinates(
72+
String groupId, String artifactId, String extension, String classifier, String version, String versionRevision) {
6673
this.groupId = Objects.requireNonNull(groupId, "Group ID");
6774
this.artifactId = Objects.requireNonNull(artifactId, "Artifact ID");
6875
this.extension = extension == null || extension.isEmpty() ? "jar" : extension;
6976
this.classifier =
7077
classifier == null || classifier.isEmpty() || "jar".equals(classifier) ? "" : classifier;
7178
this.version = version == null || version.isEmpty() ? "" : version;
79+
this.versionRevision = versionRevision;
7280
}
7381

7482
public String getGroupId() {
@@ -88,21 +96,29 @@ public String getClassifier() {
8896
}
8997

9098
public Coordinates setClassifier(String classifier) {
91-
return new Coordinates(getGroupId(), getArtifactId(), getExtension(), classifier, getVersion());
99+
return new Coordinates(getGroupId(), getArtifactId(), getExtension(), classifier, getVersion(), getVersionRevision());
92100
}
93101

94102
public Coordinates setExtension(String extension) {
95-
return new Coordinates(getGroupId(), getArtifactId(), extension, getClassifier(), getVersion());
103+
return new Coordinates(getGroupId(), getArtifactId(), extension, getClassifier(), getVersion(), getVersionRevision());
96104
}
97105

98106
public Coordinates setVersion(String version) {
99-
return new Coordinates(getGroupId(), getArtifactId(), getExtension(), getClassifier(), version);
107+
return new Coordinates(getGroupId(), getArtifactId(), getExtension(), getClassifier(), version, getVersionRevision());
108+
}
109+
110+
public Coordinates setVersionRevision(String versionRevision) {
111+
return new Coordinates(getGroupId(), getArtifactId(), getExtension(), getClassifier(), getVersion(), versionRevision);
100112
}
101113

102114
public String getExtension() {
103115
return extension;
104116
}
105117

118+
public String getVersionRevision() {
119+
return versionRevision;
120+
}
121+
106122
public String asKey() {
107123
StringBuilder coords = new StringBuilder();
108124
coords.append(groupId).append(":").append(artifactId);
@@ -133,7 +149,7 @@ public String toRepoPath() {
133149
.append("/")
134150
.append(getArtifactId())
135151
.append("-")
136-
.append(getVersion());
152+
.append(isNullOrEmpty(getVersionRevision()) ? getVersion() : getVersionRevision());
137153

138154
String classifier = getClassifier();
139155

@@ -178,14 +194,15 @@ public boolean equals(Object o) {
178194
return getGroupId().equals(that.getGroupId())
179195
&& getArtifactId().equals(that.getArtifactId())
180196
&& Objects.equals(getVersion(), that.getVersion())
197+
&& Objects.equals(getVersionRevision(), that.getVersionRevision())
181198
&& Objects.equals(getClassifier(), that.getClassifier())
182199
&& Objects.equals(getExtension(), that.getExtension());
183200
}
184201

185202
@Override
186203
public int hashCode() {
187204
return Objects.hash(
188-
getGroupId(), getArtifactId(), getVersion(), getClassifier(), getExtension());
205+
getGroupId(), getArtifactId(), getVersion(), getVersionRevision(), getClassifier(), getExtension());
189206
}
190207

191208
private boolean isNullOrEmpty(String value) {

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/GradleResolver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ private ResolutionResult parseDependencies(
181181
gradleCoordinates.getArtifactId(),
182182
extension,
183183
classifier,
184-
gradleCoordinates.getVersion());
184+
gradleCoordinates.getVersion(),
185+
dependency.getVersionRevision());
185186
addDependency(graph, coordinates, dependency, conflicts, requestedDeps, visited);
186187
// if there's a conflict and the conflicting version isn't one that's actually requested
187188
// then it's an actual conflict we want to report
@@ -275,7 +276,8 @@ private void addDependency(
275276
childCoordinates.getArtifactId(),
276277
extension,
277278
childCoordinates.getClassifier(),
278-
childCoordinates.getVersion());
279+
childCoordinates.getVersion(),
280+
childInfo.getVersionRevision());
279281
graph.addNode(child);
280282
graph.putEdge(parent, child);
281283
// if there's a conflict and the conflicting version isn't one that's actually requested

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/models/GradleResolvedDependency.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public interface GradleResolvedDependency {
3434

3535
void setVersion(String version);
3636

37+
String getVersionRevision();
38+
39+
void setVersionRevision(String versionRevision);
40+
3741
Set<String> getRequestedVersions();
3842

3943
void addRequestedVersion(String requestedVersion);

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/models/GradleResolvedDependencyImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class GradleResolvedDependencyImpl implements Serializable, GradleResolve
2525
private String group;
2626
private String name;
2727
private String version;
28+
private String versionRevision;
2829
private Set<String> requestedVersions;
2930
private boolean conflict;
3031
private List<GradleResolvedDependency> children;
@@ -61,6 +62,14 @@ public void setVersion(String version) {
6162
this.version = version;
6263
}
6364

65+
public String getVersionRevision() {
66+
return versionRevision;
67+
}
68+
69+
public void setVersionRevision(String versionRevision) {
70+
this.versionRevision = versionRevision;
71+
}
72+
6473
public Set<String> getRequestedVersions() {
6574
return requestedVersions;
6675
}

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/gradle/plugin/GradleDependencyModelBuilder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ private GradleResolvedDependency walkResolvedComponent(
268268
info = new GradleResolvedDependencyImpl();
269269
info.setGroup(component.getModuleVersion().getGroup());
270270
info.setName(component.getModuleVersion().getName());
271-
info.setVersion(component.getModuleVersion().getVersion());
271+
String version = component.getModuleVersion().getVersion();
272+
info.setVersion(version);
273+
274+
// For snapshot dependencies, extract the timestamped version from the component ID
275+
// Note: this is unsafe, is there a better way of obtaining the timestamp for an snapshot? I could not find any
276+
if (component.getId().getClass().getName().contains("MavenUniqueSnapshotComponentIdentifier")) {
277+
String snapshot_version = version.substring(0, version.length() - "-SNAPSHOT".length());
278+
// Extract timestamped version from format: group:artifact:version:timestamp-buildnum
279+
String snapshotId = snapshot_version + "-" + component.getId().toString().split(":")[3];
280+
info.setVersionRevision(snapshotId);
281+
}
272282
}
273283

274284
info.addRequestedVersion(info.getVersion()); // add a new version that may have been requested

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/lockfile/V2LockFile.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ public Map<String, Object> render() {
216216
Map<String, Object> artifactValue =
217217
artifacts.computeIfAbsent(shortKey, k -> new TreeMap<>());
218218
artifactValue.put("version", coords.getVersion());
219+
220+
// Add version_revision for reproducible builds when available
221+
if (coords.getVersionRevision() != null && !coords.getVersionRevision().isEmpty()) {
222+
artifactValue.put("version_revision", coords.getVersionRevision());
223+
}
219224

220225
String classifier;
221226
if (coords.getClassifier() == null || coords.getClassifier().isEmpty()) {

private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/remote/Downloader.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ public DownloadResult download(Coordinates coords) {
8484
return result;
8585
}
8686

87-
// Are we dealing with a packaging dep? Download the `pom.xml` and check
88-
String originalTarget = coords.toRepoPath();
89-
String pomName = String.format("%s-%s.pom", coords.getArtifactId(), coords.getVersion());
90-
String pom = Paths.get(originalTarget).getParent().resolve(pomName).toString();
91-
87+
String pom = coords.setExtension("pom").toRepoPath();
9288
DownloadResult pomResult = performDownload(coords, pom);
9389
if (pomResult == null) {
9490
System.out.println(

tests/custom_maven_install/regression_testing_gradle_install.json

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": 583824883,
4-
"__RESOLVED_ARTIFACTS_HASH": -2112507832,
3+
"__INPUT_ARTIFACTS_HASH": 509276490,
4+
"__RESOLVED_ARTIFACTS_HASH": 1797498681,
55
"artifacts": {
66
"androidx.activity:activity-ktx:aar": {
77
"shasums": {
@@ -243,6 +243,37 @@
243243
},
244244
"version": "1.0.0"
245245
},
246+
"com.google.errorprone:error_prone_annotations": {
247+
"shasums": {
248+
"jar": "77440e270b0bc9a249903c5a076c36a722c4886ca4f42675f2903a1c53ed61a5"
249+
},
250+
"version": "2.36.0"
251+
},
252+
"com.google.guava:failureaccess": {
253+
"shasums": {
254+
"jar": "cbfc3906b19b8f55dd7cfd6dfe0aa4532e834250d7f080bd8d211a3e246b59cb"
255+
},
256+
"version": "1.0.3"
257+
},
258+
"com.google.guava:guava": {
259+
"shasums": {
260+
"jar": "79abe7953803b20d1deb5f36283d4d640c7aacbdb1ddd7601aae369b1633e903"
261+
},
262+
"version": "999.0.0-HEAD-jre-SNAPSHOT",
263+
"version_revision": "999.0.0-HEAD-jre-20250623.150948-114"
264+
},
265+
"com.google.guava:listenablefuture": {
266+
"shasums": {
267+
"jar": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99"
268+
},
269+
"version": "9999.0-empty-to-avoid-conflict-with-guava"
270+
},
271+
"com.google.j2objc:j2objc-annotations": {
272+
"shasums": {
273+
"jar": "88241573467ddca44ffd4d74aa04c2bbfd11bf7c17e0c342c94c9de7a70a7c64"
274+
},
275+
"version": "3.0.0"
276+
},
246277
"org.jetbrains.kotlin:kotlin-stdlib": {
247278
"shasums": {
248279
"jar": "042a1cd1ac976cdcfe5eb63f1d8e0b0b892c9248e15a69c8cfba495d546ea52a"
@@ -290,6 +321,12 @@
290321
"jar": "ace2a10dc8e2d5fd34925ecac03e4988b2c0f851650c94b8cef49ba1bd111478"
291322
},
292323
"version": "13.0"
324+
},
325+
"org.jspecify:jspecify": {
326+
"shasums": {
327+
"jar": "1fad6e6be7557781e4d33729d49ae1cdc8fdda6fe477bb0cc68ce351eafdfbab"
328+
},
329+
"version": "1.0.0"
293330
}
294331
},
295332
"conflict_resolution": {
@@ -598,6 +635,13 @@
598635
"androidx.tracing:tracing:aar": [
599636
"androidx.annotation:annotation"
600637
],
638+
"com.google.guava:guava": [
639+
"com.google.errorprone:error_prone_annotations",
640+
"com.google.guava:failureaccess",
641+
"com.google.guava:listenablefuture",
642+
"com.google.j2objc:j2objc-annotations",
643+
"org.jspecify:jspecify"
644+
],
601645
"org.jetbrains.kotlin:kotlin-stdlib": [
602646
"org.jetbrains.kotlin:kotlin-stdlib-common",
603647
"org.jetbrains:annotations"
@@ -635,6 +679,36 @@
635679
"androidx.concurrent:concurrent-futures": [
636680
"androidx.concurrent.futures"
637681
],
682+
"com.google.errorprone:error_prone_annotations": [
683+
"com.google.errorprone.annotations",
684+
"com.google.errorprone.annotations.concurrent"
685+
],
686+
"com.google.guava:failureaccess": [
687+
"com.google.common.util.concurrent.internal"
688+
],
689+
"com.google.guava:guava": [
690+
"com.google.common.annotations",
691+
"com.google.common.base",
692+
"com.google.common.base.internal",
693+
"com.google.common.cache",
694+
"com.google.common.collect",
695+
"com.google.common.escape",
696+
"com.google.common.eventbus",
697+
"com.google.common.graph",
698+
"com.google.common.hash",
699+
"com.google.common.html",
700+
"com.google.common.io",
701+
"com.google.common.math",
702+
"com.google.common.net",
703+
"com.google.common.primitives",
704+
"com.google.common.reflect",
705+
"com.google.common.util.concurrent",
706+
"com.google.common.xml",
707+
"com.google.thirdparty.publicsuffix"
708+
],
709+
"com.google.j2objc:j2objc-annotations": [
710+
"com.google.j2objc.annotations"
711+
],
638712
"org.jetbrains.kotlin:kotlin-stdlib": [
639713
"kotlin",
640714
"kotlin.annotation",
@@ -713,6 +787,9 @@
713787
"org.jetbrains:annotations": [
714788
"org.intellij.lang.annotations",
715789
"org.jetbrains.annotations"
790+
],
791+
"org.jspecify:jspecify": [
792+
"org.jspecify.annotations"
716793
]
717794
},
718795
"repositories": {
@@ -758,15 +835,23 @@
758835
"androidx.startup:startup-runtime:aar",
759836
"androidx.tracing:tracing:aar"
760837
],
838+
"https://oss.sonatype.org/content/repositories/snapshots/": [
839+
"com.google.guava:guava"
840+
],
761841
"https://repo1.maven.org/maven2/": [
842+
"com.google.errorprone:error_prone_annotations",
843+
"com.google.guava:failureaccess",
844+
"com.google.guava:listenablefuture",
845+
"com.google.j2objc:j2objc-annotations",
762846
"org.jetbrains.kotlin:kotlin-stdlib",
763847
"org.jetbrains.kotlin:kotlin-stdlib-common",
764848
"org.jetbrains.kotlin:kotlin-stdlib-jdk7",
765849
"org.jetbrains.kotlin:kotlin-stdlib-jdk8",
766850
"org.jetbrains.kotlinx:kotlinx-coroutines-android",
767851
"org.jetbrains.kotlinx:kotlinx-coroutines-core",
768852
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm",
769-
"org.jetbrains:annotations"
853+
"org.jetbrains:annotations",
854+
"org.jspecify:jspecify"
770855
]
771856
},
772857
"services": {

0 commit comments

Comments
 (0)