Feature/maven version range#436
Conversation
For instance, it's now possible to run with `-Dmaven=[3.0,4.0\)` to let the plugin resolve the highest available version in that range.
|
|
||
| <properties> | ||
| <version.mockito>4.11.0</version.mockito> | ||
| <version.mockito>5.23.0</version.mockito> |
There was a problem hiding this comment.
Bumped to use mockStatic and mockConstruction
|
-1 Why not use RepositorySystem, do not replicate the logic. |
| </dependency> | ||
| <dependency> | ||
| <groupId>org.codehaus.plexus</groupId> | ||
| <artifactId>plexus-utils</artifactId> |
There was a problem hiding this comment.
Added since MetadataXpp3Reader.read() throws XmlPullParserException from this package.
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-params</artifactId> |
There was a problem hiding this comment.
Added to use @ParameterizedTest
|
You most probably want this instead #437 |
|
Feel free to incorporate that instead. |
I was thinking about something like this (currently a draft): String resolveVersionRange(String version) {
try {
Artifact artifact = new DefaultArtifact("org.apache.maven:apache-maven:" + version);
VersionRangeRequest versionRangeRequest = new VersionRangeRequest();
versionRangeRequest.setArtifact(artifact);
versionRangeRequest.setRepositories(session.getCurrentProject().getRemotePluginRepositories());
return repositorySystem
.resolveVersionRange(repositorySystemSession, versionRangeRequest)
.getHighestVersion()
.toString();
} catch (VersionRangeResolutionException e) {
return version;
}
}Maybe I'm missing something, I'll check your suggestion in the next days |
|
Yes, that looks good as well, but several remarks:
Otherwise, yes, this is the right way, no need to fiddle with XML parsing etc. |
String resolveMavenVersion(String version) {
try {
Artifact artifact = new DefaultArtifact("org.apache.maven:apache-maven:" + version);
VersionRangeRequest request = new VersionRangeRequest(
artifact, session.getCurrentProject().getRemotePluginRepositories(), RELEASE, "wrapper"); // <-- here
return repositorySystem
.resolveVersionRange(repositorySystemSession, request)
.getHighestVersion()
.toString();
} catch (VersionRangeResolutionException e) {
return version;
}
}What do you think? Is there anything else to address? Edit: |
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
Problem
As per the usage docs, bumping the Maven version requires manually going on Maven Central to get the latest. It would be nice having the plugin resolve the highest available version automatically.
Proposed solution
Maven already supports Dependency Version Requirement Specification, allowing the definition of a range instead of a fixed one. Though it's not advisable to rely on such a mechanism to manage regular dependencies of an application for the sake of reproducible builds, the wrapper is an external tool for which this issue doesn't apply.
Available Maven versions are taken from maven-metadata.xml.
Rationale
Having a native way to automatically bump the Maven version let us schedule a simple wrapper execution. For instance:
./mvnw wrapper:wrapper -Dmaven=3.9.16: fixed versions are considered valid ranges, so no breaking change../mvnw wrapper:wrapper -Dmaven="[3.0,4.0-alpha)": allows the resolution of the latest3.x.xversion, excluding currently non-stable4.x.xversions.Moreover, this is done without relying on external tools such as GitHub actions (as proposed in #331) or bots like Renovate (as proposed in #249).