This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new e97123e97e Name the missing goal when @InjectMojo matches no mojo in
the plugin descriptor
e97123e97e is described below
commit e97123e97eecdb1a12d2a00382a0d4faadfbfa5a
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 3 23:04:56 2026 +0000
Name the missing goal when @InjectMojo matches no mojo in the plugin
descriptor
---
.../apache/maven/testing/plugin/MojoExtension.java | 8 +++-
.../plugin/MojoExtensionMissingGoalTest.java | 45 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
b/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
index 98d0c6afa8..7d10142110 100644
---
a/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
+++
b/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
@@ -517,7 +517,13 @@ private MojoExecution createMojoExecution() {
mes.setDescriptor(md);
}
}
- requireNonNull(mes.descriptor());
+ if (mes.descriptor() == null) {
+ throw new IllegalStateException("No mojo with goal '"
+ goal + "' in plugin "
+ + pluginDescriptor.getId() + "; available
goals: "
+ + pluginDescriptor.getMojos().stream()
+ .map(MojoDescriptor::getGoal)
+ .collect(Collectors.toList()));
+ }
}
PluginStub plugin = new PluginStub();
plugin.setDescriptor(pluginDescriptor);
diff --git
a/impl/maven-testing/src/test/java/org/apache/maven/testing/plugin/MojoExtensionMissingGoalTest.java
b/impl/maven-testing/src/test/java/org/apache/maven/testing/plugin/MojoExtensionMissingGoalTest.java
new file mode 100644
index 0000000000..cd4331d3cb
--- /dev/null
+++
b/impl/maven-testing/src/test/java/org/apache/maven/testing/plugin/MojoExtensionMissingGoalTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.testing.plugin;
+
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.di.Injector;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@MojoTest
+class MojoExtensionMissingGoalTest {
+
+ @Inject
+ Injector injector;
+
+ @Test
+ @InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:missing")
+ void missingGoalIsReportedByName() {
+ Exception e = assertThrows(Exception.class, () ->
injector.getInstance(MojoExecution.class));
+ String messages = "";
+ for (Throwable t = e; t != null; t = t.getCause()) {
+ messages += t.getClass().getName() + ": " + t.getMessage() +
System.lineSeparator();
+ }
+ assertTrue(messages.contains("missing"), "exception chain should name
the missing goal, got: " + messages);
+ }
+}