From 792aa03d2325a4279ce9febf4a07f2e8684e3177 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Sat, 25 Jul 2026 02:11:36 +0200 Subject: [PATCH 1/2] Skip evaluate-artifact IT on Maven 4 until expression evaluation is fixed The evaluate-artifact-with-expression-with-output IT fails on Maven 4 because PluginParameterExpressionEvaluator does not resolve ${project.*} expressions when the session is cloned via setCurrentProject(). This causes handleResponse() to treat the expression as invalid and skip writing the output file. Skip on Maven 4 until #173 is resolved, matching the pattern used by other ITs (e.g. active-profiles_multimodule, evaluate-settings-servers). Co-Authored-By: Claude Opus 4.6 --- .../invoker.properties | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties b/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties new file mode 100644 index 0000000..17f6f03 --- /dev/null +++ b/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties @@ -0,0 +1,19 @@ +# 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. + +# not on Maven 4 until fixed https://github.com/apache/maven-help-plugin/issues/173 +invoker.maven.version = 4- From 7bd00bb767489399517958165d1712f44cdfd0e8 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Sat, 25 Jul 2026 02:29:26 +0200 Subject: [PATCH 2/2] Fix evaluate goal failing on Maven 4 when using artifact parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The evaluate goal failed on Maven 4 when the "artifact" parameter was set because getEvaluator() used MojoDescriptorCreator to re-resolve the "help:evaluate" mojo descriptor from scratch. In Maven 4, this resolution attempted to resolve maven-help-plugin:3.5.1 from an empty repository list, causing a "could not be resolved" error. Instead of re-resolving the mojo descriptor, use the MojoExecution that Maven already provides via ${mojoExecution} parameter injection. This is both simpler and correct — the running mojo already has its descriptor available, and there is no need to resolve it again through MojoDescriptorCreator. Co-Authored-By: Claude Opus 4.6 --- .../invoker.properties | 19 ---------- .../maven/plugins/help/EvaluateMojo.java | 36 ++++++------------- 2 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties b/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties deleted file mode 100644 index 17f6f03..0000000 --- a/src/it/projects/evaluate-artifact-with-expression-with-output/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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. - -# not on Maven 4 until fixed https://github.com/apache/maven-help-plugin/issues/173 -invoker.maven.version = 4- diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java index 4121208..163a37f 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -38,7 +38,6 @@ import com.thoughtworks.xstream.converters.collections.PropertiesConverter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; @@ -46,7 +45,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -124,6 +122,12 @@ public class EvaluateMojo extends AbstractHelpMojo { @Parameter(defaultValue = "${settings}", readonly = true, required = true) private Settings settings; + /** + * The current mojo execution, used to create the expression evaluator. + */ + @Parameter(defaultValue = "${mojoExecution}", readonly = true, required = true) + private MojoExecution mojoExecution; + // ---------------------------------------------------------------------- // Instance variables // ---------------------------------------------------------------------- @@ -143,20 +147,10 @@ public class EvaluateMojo extends AbstractHelpMojo { */ private final InputHandler inputHandler; - /** - * Component used to get mojo descriptors. - */ - private MojoDescriptorCreator mojoDescriptorCreator; - @Inject - public EvaluateMojo( - ProjectBuilder projectBuilder, - RepositorySystem repositorySystem, - InputHandler inputHandler, - MojoDescriptorCreator mojoDescriptorCreator) { + public EvaluateMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem, InputHandler inputHandler) { super(projectBuilder, repositorySystem); this.inputHandler = inputHandler; - this.mojoDescriptorCreator = mojoDescriptorCreator; } // ---------------------------------------------------------------------- @@ -223,20 +217,12 @@ private void validateParameters() { /** * @return a lazy loading evaluator object. - * @throws MojoFailureException if any reflection exceptions occur or missing components. */ - private PluginParameterExpressionEvaluator getEvaluator() throws MojoFailureException { + private PluginParameterExpressionEvaluator getEvaluator() { if (evaluator == null) { - MojoDescriptor mojoDescriptor; - try { - mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor("help:evaluate", session, project); - } catch (Exception e) { - throw new MojoFailureException("Failure while evaluating.", e); - } - MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); - - // Maven 3: PluginParameterExpressionEvaluator gets the current project from the session: - // so we need to clone the session to set the right project + // PluginParameterExpressionEvaluator gets the current project from the session, + // so we need to clone the session to set the right project (which may have been + // changed by the "artifact" parameter). MavenSession clonedSession = session.clone(); clonedSession.setCurrentProject(project); evaluator = new PluginParameterExpressionEvaluator(clonedSession, mojoExecution);