bazelbuild / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Apache License 2.0
316 stars 236 forks source link

Snapshot artifacts are not resolved by the Maven resolver #1147

Open tharakadesilva opened 1 month ago

tharakadesilva commented 1 month ago

In Artifactory, we have a repository called maven and inside maven, we can assume we have a library under maven/my/org/my-library/0.3.0-SNAPSHOT.

In this index, we have the following files:

However, when we try to refer to it with something like maven.artifact("my.org", "my-library", "0.3.0-SNAPSHOT"), we are getting:

java.lang.RuntimeException: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact my.org:my-library:pom:0.3.0-SNAPSHOT
        at com.github.bazelbuild.rules_jvm_external.resolver.maven.MavenResolver.resolve(MavenResolver.java:247)
        at com.github.bazelbuild.rules_jvm_external.resolver.cmd.Main.main(Main.java:74)
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact my.org:my-library:pom:0.3.0-SNAPSHOT
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:464)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:261)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:243)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:234)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:175)
        at org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector.resolveCachedArtifactDescriptor(BfDependencyCollector.java:464)
        at org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector.resolveDescriptorForVersion(BfDependencyCollector.java:450)
        at org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector.lambda$resolveArtifactDescriptorAsync$1(BfDependencyCollector.java:417)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
        at org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector.lambda$resolveArtifactDescriptorAsync$4(BfDependencyCollector.java:416)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

This was resolved with Coursier and the lock file was generated.

Additional Information:

Bazel Version: 6.5.0 rules_jvm_eternal Version: 6.1 Operating System: MacOS

cheister commented 2 days ago

Just noting, snapshot artifacts will never work for maven_installs that use a lockfile since the version (0.3.0-20240503.081128-2) and SHA of the snapshot jar can change without changing the artifact version (0.3.0-SNAPSHOT), which would make the lockfile incorrect.

Since the maven resolver requires a lock file we would have to add a feature for the maven resolver to not require the lockfile before looking at supporting snapshot repos.