You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elmuerte (via GitHub)" <gi...@apache.org> on 2025/12/03 15:10:45 UTC

[I] MojoExtension's parameter resolving conflicts with other JUnit parameter resolvers [maven-plugin-testing]

elmuerte opened a new issue, #244:
URL: https://github.com/apache/maven-plugin-testing/issues/244

   ### Affected version
   
   3.4.0
   
   ### Bug description
   
   `MojoExtension`/`MojoTest` cannot be used with any other JUnit extension which also provides parameter resolving. `MojoExtension`'s `supportsParameter` is too broad as it will match any parameter if the method has an `InjectMojo` annotation.
   
   The following example will fail
   
   ```java
   @ExtendWith({MojoExtension.class, WireMockExtension.class})
   class FindingsMojoIntegrationTest {
       @Test
       @InjectMojo(
               goal = "findings",
               pom = "src/test/resources/projects/run/pom.xml")
       void someTest(FindingsMojo findingsMojo, WireMockRuntimeInfo wmri) {
       }
   }
   ```
   
   JUnit will throw the exception
   
   ```
   org.junit.jupiter.api.extension.ParameterResolutionException: Discovered multiple competing ParameterResolvers for parameter [com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo arg1] in method [void io.github.pmckeown.dependencytrack.finding.FindingsMojoIntegrationTest.setUp(io.github.pmckeown.dependencytrack.finding.FindingsMojo,com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo)]: org.apache.maven.api.plugin.testing.MojoExtension@106802ea, com.github.tomakehurst.wiremock.junit5.WireMockExtension@785ef70f
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
   ```
   
   This is due to the following code
   https://github.com/apache/maven-plugin-testing/blob/3d28d1ef3f584e27762528de74624e8bf0c234dc/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java#L146-L150
   
   `parameterContext.isAnnotated(InjectMojo.class)` would always return false as `InjectMojo` can only be used on a method, and not a parameter. Then it it will check if the method contains the `InjectMojo` annotation without checking if the affecting parameter is even a subclass of `Mojo`. This would result in the extension to assign the resolved Mojo to every parameter (which JUnit will also reject due to type mismatches.)
   
   So the the `supportsParameter` implementation needs to be fixed to also include `Mojo.class.isAssignableFrom(parameterContext.getParameter().getType())`.
   
   Further more, it would be nice if `InjectMojo` and `MojoParameter` annotations could also be used on the parameter itself, as the code also takes that into account.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] MojoExtension's parameter resolving conflicts with other JUnit parameter resolvers [maven-plugin-testing]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on issue #244:
URL: https://github.com/apache/maven-plugin-testing/issues/244#issuecomment-3694740603

   fixed in #246 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] MojoExtension's parameter resolving conflicts with other JUnit parameter resolvers [maven-plugin-testing]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski closed issue #244: MojoExtension's parameter resolving conflicts with other JUnit parameter resolvers
URL: https://github.com/apache/maven-plugin-testing/issues/244


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org