You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2026/07/24 20:57:23 UTC

(maven-wrapper) branch range created (now 92578c3)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a change to branch range
in repository https://gitbox.apache.org/repos/asf/maven-wrapper.git


      at 92578c3  Allow version constraint

This branch includes the following new commits:

     new 92578c3  Allow version constraint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-wrapper) 01/01: Allow version constraint

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch range
in repository https://gitbox.apache.org/repos/asf/maven-wrapper.git

commit 92578c3138366792c7bde87ebac893b29cde2ee4
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Jul 24 22:56:00 2026 +0200

    Allow version constraint
    
    and not range, as this can be `[3.6.3,3.8.8],[3.9.11,4]` just like
    for dependencies in POM.
---
 .../apache/maven/plugins/wrapper/WrapperMojo.java  | 42 +++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
index b38a0e4..e2bf6cc 100644
--- a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
+++ b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
@@ -29,6 +29,8 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
@@ -48,6 +50,12 @@ import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.resolution.ArtifactRequest;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.eclipse.aether.resolution.ArtifactResult;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.util.version.GenericVersionScheme;
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.Version;
+import org.eclipse.aether.version.VersionConstraint;
 
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
@@ -211,7 +219,7 @@ public class WrapperMojo extends AbstractMojo {
                     + " cannot work with mvnd, please set type to '" + TYPE_ONLY_SCRIPT + "'.");
         }
 
-        mavenVersion = getVersion(mavenVersion, Maven.class, "org.apache.maven/maven-core");
+        mavenVersion = resolveMavenVersion(getVersion(mavenVersion, Maven.class, "org.apache.maven/maven-core"));
         String wrapperVersion = getVersion(null, this.getClass(), "org.apache.maven.plugins/maven-wrapper-plugin");
 
         final Artifact artifact = downloadWrapperDistribution(wrapperVersion);
@@ -376,6 +384,38 @@ public class WrapperMojo extends AbstractMojo {
         return version;
     }
 
+    private String resolveMavenVersion(String version) {
+        try {
+            VersionConstraint constraint = new GenericVersionScheme().parseVersionConstraint(version);
+            if (constraint.getVersion() != null) {
+                return constraint.getVersion().toString();
+            } else {
+                Artifact artifact = new DefaultArtifact("org.apache.maven:apache-maven:bin:zip:" + version);
+                VersionRangeRequest request = new VersionRangeRequest(
+                        artifact,
+                        Collections.singletonList(
+                                new RemoteRepository.Builder(DEFAULT_REPO_ID, "default", DEFAULT_REPO_URL).build()),
+                        "wrapper");
+                List<Version> versions = repositorySystem
+                        .resolveVersionRange(repositorySystemSession, request)
+                        .getVersions();
+                if (!versions.isEmpty()) {
+                    versions.sort(Comparator.reverseOrder());
+                    for (Version ver : versions) {
+                        String v = ver.toString();
+                        artifact = artifact.setVersion(v);
+                        if (!artifact.isSnapshot()) {
+                            return v;
+                        }
+                    }
+                }
+                return version;
+            }
+        } catch (InvalidVersionSpecificationException | VersionRangeResolutionException e) {
+            return version;
+        }
+    }
+
     /**
      * Determine the repository URL to download Wrapper and Maven from.
      */