From 63a8c03cc07d88f784fcf52f98fd78102b681544 Mon Sep 17 00:00:00 2001 From: Abhinav Tarigoppula Date: Wed, 19 Aug 2026 06:20:42 +0530 Subject: [PATCH 1/2] Fix #393: stop reading LATEST from the deprecated Artifact constant getAetherArtifact() filled in a missing version from org.apache.maven.artifact.Artifact.LATEST_VERSION, which Maven 4 deprecates, and that import was the only thing the class used it for. The value stays "LATEST", now a private constant. Passing null instead, as the issue suggests, would not work: Aether's DefaultArtifact normalises a null version to the empty string, so two-part coordinates would resolve against g:a:pom: rather than the newest version. Adds a test for the coordinate parsing, which had none. --- .../maven/plugins/help/AbstractHelpMojo.java | 11 ++- .../plugins/help/AbstractHelpMojoTest.java | 68 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java index 42178756..545f3aff 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java @@ -23,7 +23,6 @@ import java.io.Writer; import java.nio.file.Files; -import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.plugin.AbstractMojo; @@ -48,6 +47,14 @@ * @since 2.1 */ public abstract class AbstractHelpMojo extends AbstractMojo { + + /** + * The metaversion Aether resolves to the newest available version, used when the caller gives + * coordinates without one. Spelled out here rather than read from + * {@code org.apache.maven.artifact.Artifact#LATEST_VERSION}, which Maven 4 deprecates. + */ + private static final String LATEST_VERSION = "LATEST"; + /** The maximum length of a display line. */ protected static final int LINE_LENGTH = 79; @@ -144,7 +151,7 @@ protected org.eclipse.aether.artifact.Artifact getAetherArtifact(String artifact case 2: groupId = artifactParts[0]; artifactId = artifactParts[1]; - version = Artifact.LATEST_VERSION; + version = LATEST_VERSION; break; case 3: groupId = artifactParts[0]; diff --git a/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java b/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java new file mode 100644 index 00000000..fddea047 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.help; + +import org.apache.maven.plugin.MojoExecutionException; +import org.eclipse.aether.artifact.Artifact; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Tests the coordinate parsing in {@link AbstractHelpMojo#getAetherArtifact(String, String)}. + */ +class AbstractHelpMojoTest { + + private final AbstractHelpMojo mojo = new AbstractHelpMojo(null, null) { + @Override + public void execute() {} + }; + + @Test + void coordinatesWithoutAVersionGetTheLatestMetaversion() throws Exception { + Artifact artifact = mojo.getAetherArtifact("org.apache.maven:maven-core", "pom"); + + assertEquals("org.apache.maven", artifact.getGroupId()); + assertEquals("maven-core", artifact.getArtifactId()); + assertEquals("pom", artifact.getExtension()); + // The literal, not the constant: leaving the version out has to keep producing a + // metaversion the resolver recognises. A null version would arrive here as "" instead. + assertEquals("LATEST", artifact.getVersion()); + } + + @Test + void coordinatesWithAVersionKeepIt() throws Exception { + Artifact artifact = mojo.getAetherArtifact("org.apache.maven:maven-core:3.9.16", "pom"); + + assertEquals("3.9.16", artifact.getVersion()); + } + + @Test + void coordinatesWithTooManyPartsAreRejected() { + assertThrows( + MojoExecutionException.class, + () -> mojo.getAetherArtifact("org.apache.maven:maven-core:3.9.16:extra", "pom")); + } + + @Test + void emptyCoordinatesAreRejected() { + assertThrows(IllegalArgumentException.class, () -> mojo.getAetherArtifact("", "pom")); + } +} From 039baa82e06df8d83e74277e2c2f03a265b19db8 Mon Sep 17 00:00:00 2001 From: Abhinav Tarigoppula Date: Wed, 19 Aug 2026 18:11:29 +0530 Subject: [PATCH 2/2] Inline the LATEST literal instead of a single-use constant --- .../apache/maven/plugins/help/AbstractHelpMojo.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java index 545f3aff..2d4291c8 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java @@ -48,13 +48,6 @@ */ public abstract class AbstractHelpMojo extends AbstractMojo { - /** - * The metaversion Aether resolves to the newest available version, used when the caller gives - * coordinates without one. Spelled out here rather than read from - * {@code org.apache.maven.artifact.Artifact#LATEST_VERSION}, which Maven 4 deprecates. - */ - private static final String LATEST_VERSION = "LATEST"; - /** The maximum length of a display line. */ protected static final int LINE_LENGTH = 79; @@ -151,7 +144,8 @@ protected org.eclipse.aether.artifact.Artifact getAetherArtifact(String artifact case 2: groupId = artifactParts[0]; artifactId = artifactParts[1]; - version = LATEST_VERSION; + // Not null: Aether normalises a null version to "", not to a metaversion. + version = "LATEST"; break; case 3: groupId = artifactParts[0];