Skip to content
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

Dependency version SNAPSHOT is not recognized as snapshot version #5613

Closed
floscher opened this issue Jun 1, 2018 · 7 comments
Closed

Dependency version SNAPSHOT is not recognized as snapshot version #5613

floscher opened this issue Jun 1, 2018 · 7 comments
Labels
a:bug closed:not-fixed Indicates the issue was not fixed and is not planned to be in:dependency-resolution engine metadata

Comments

@floscher
Copy link

floscher commented Jun 1, 2018

Expected Behavior

When I specify a dependency as

repositories {
  maven {
    url "https://example.org/maven"
  }
}
dependencies {
  implementation "org.example:myapp:SNAPSHOT"
}

I expect that Gradle downloads the latest snapshot from the given Maven repo.

The URL of the downloaded artifact might look something like this:
https://example.org/maven/org/example/myapp/SNAPSHOT/myapp-20180601.010203-123.jar

In the process I'd expect Gradle to consult
https://example.org/maven/org/example/myapp/SNAPSHOT/maven-metadata.xml
to find the latest version.

Current Behavior

Gradle fails with the following message:

   > Could not find org.example:myapp:SNAPSHOT.
     Searched in the following locations:
         https://example.org/maven/org/example/myapp/SNAPSHOT/myapp-SNAPSHOT.pom
         https://example.org/maven/org/example/myapp/SNAPSHOT/myapp-SNAPSHOT.jar

Gradle does not recognize that SNAPSHOT is a snapshot version (like 1.0-SNAPSHOT). It treats this version number like a "normal" version number (like 1.2.3).

I played around a bit with this and Gradle seems to only treat versions matching (.+)-SNAPSHOT as such snapshot versions, but https://maven.apache.org/glossary.html clearly states that SNAPSHOT without anything else should also be treated as a snapshot version.

Context

I tried using the following repository in one of my builds: https://josm.openstreetmap.de/nexus/content/repositories/snapshots/

When adding the dependency org.openstreetmap.josm:josm:SNAPSHOT, Gradle errors out because it can't find the dependency.

Steps to Reproduce (for bugs)

See "current behaviour". Add such a dependency and run e.g. ./gradlew dependencies. Under "context" you'll find an example dependency.

@floscher
Copy link
Author

floscher commented Jun 2, 2018

This is the line that causes the problem:

This should fix the issue:

diff --git a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/resolver/MavenResolver.java b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/resolver/MavenResolver.java
index 62d5114b811..ae10e82473b 100644
--- a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/resolver/MavenResolver.java
+++ b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/resolver/MavenResolver.java
@@ -264,7 +264,7 @@ public class MavenResolver extends ExternalResourceResolver<MavenModuleResolveMe
     }
 
     protected static boolean isNonUniqueSnapshot(ModuleComponentIdentifier moduleComponentIdentifier) {
-        return moduleComponentIdentifier.getVersion().endsWith("-SNAPSHOT");
+        return moduleComponentIdentifier.getVersion().endsWith("-SNAPSHOT") || "SNAPSHOT".equals(moduleComponentIdentifier.getVersion());
     }
 
     private MavenUniqueSnapshotComponentIdentifier composeSnapshotIdentifier(ModuleComponentIdentifier moduleComponentIdentifier, MavenUniqueSnapshotModuleSource uniqueSnapshotVersion) {

Maybe it needs some additonal work, but the main cause should be removed.

@ljacomet
Copy link
Member

Thanks for the report.

This issue seems very specific to Maven corner case. We have no bandwidth to work on it for now.
However feel free to submit a pull request fixing this problem, which will need proper test coverage.

@bigdaz bigdaz added the a:bug label Oct 16, 2018
@angeloudy
Copy link

@floscher Did you find a workaround to this problem?

@floscher
Copy link
Author

@angeloudy No I didn't find a workaround.

@cldvr
Copy link

cldvr commented Mar 10, 2020

Like @floscher pointed out, Maven - Glossary clearly states:

The version can either be the string SNAPSHOT itself, indicating “the very latest” development version, or something like 1.1-SNAPSHOT...

This particular use case is not very common and it's not well documented, but it's perfectly valid. Having a quick look to Maven sources, one can find implementation details in several places specifically to support this use case, so it's not accidental!

My minimal pull request fixes this issue, improving Gradle's compatibility with Maven.

Nevertheless, experimenting with a couple demo projects with real dependencies, one difference remains...

Maven dependencies resolution:

$ mvn -V dependency:resolve
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
...
[INFO] --- maven-dependency-plugin:2.8:resolve (default-cli) @ maven-demo ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    org.slf4j:slf4j-api:jar:2.0.0-alpha1:compile
[INFO]    org.apache.logging.log4j:log4j-api:jar:3.0.0-SNAPSHOT:compile
[INFO]    org.openstreetmap.josm:josm:jar:20200310.023250-1430:compile

Gradle dependencies resolution:

$ gradle -v
Gradle 6.3-20200302003000+0000

$ gradle -q dependencies --configuration default
...
default - Configuration for default artifacts.
+--- org.slf4j:slf4j-api:2.0.0-alpha1
+--- org.apache.logging.log4j:log4j-api:3.0.0-SNAPSHOT
\--- org.openstreetmap.josm:josm:SNAPSHOT

As you can see above with the josm dependency, Maven replaces SNAPSHOT with the corresponding timestamp while Gradle does not. This is just a display discrepancy, since both tools properly handle the internal conversion. I reckon that Gradle display is better, more coherent when using SNAPSHOT for both log4j-api and josm.

cldvr added a commit to cldvr/gradle that referenced this issue Apr 17, 2020
Issue: gradle#5613

Maven compatibility bug fix, now accepting the bare ’SNAPSHOT’ verbatim or the ‘-SNAPSHOT’ suffix for the version string format.

Fixes gradle#5613

Signed-off-by: Cláudio Vieira <cldvr@claudiovieira.me>
@natario1
Copy link

Any plan for fixing this?

@ljacomet
Copy link
Member

There is no plan to fix this from the Gradle core team as this does not seem widely used.
The PR proposed was lacking test coverage to be merged.

If someone feels like picking this up, please take a look at the existing PR and make sure test coverage is added. We can then re-open this issue.

@ljacomet ljacomet added closed:not-fixed Indicates the issue was not fixed and is not planned to be in:dependency-resolution engine metadata and removed in:dependency-management labels Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug closed:not-fixed Indicates the issue was not fixed and is not planned to be in:dependency-resolution engine metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants