4
votes

I have a mojo annotated with @requiresDependencyResolution test.

It works for multi-module projects with a single layer of nesting, but a user has reported an issue with a structure such as below.

 -- my_project
    |
    -- pom.xml
    -- submodule1
       |
       -- pom.xml
    -- submodule2
       |
       -- pom.xml
       -- submodule21
         |
         -- pom.xml
       -- submodule22
         |
         -- pom.xml

If submodule21 depends on submodule1 maven reports

Failed to execute goal on project submodule21: Could not resolve dependencies for project org.my:submodule21:jar:1.0-SNAPSHOT: Could not find artifact org.my:submodule1:jar:1.0-SNAPSHOT

Removing the requiresDependencyResolution=test annotation prevents this problem but then I do not have access to the information I require for the mojo to run.

From brief scan of the surefire code on github, it looks to also use requiresDependencyResolution=test but is able to run against this project without issue.

https://github.com/apache/maven-surefire/blob/master/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java

https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java

The only obvious difference from my own code is that it uses java annotations rather than old style javadoc ones.

How is the surefire mojo achieving this?

My code is

http://code.google.com/p/pitestrunner/source/browse/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java

Example project displaying issue

http://code.google.com/p/pitestrunner/issues/detail?id=71

1
Based on the error message i would assume the dependenies within this multi-module build are not correct, cause if the dependencies are correct the build should work without any problems without installing the artifacts into local repository via mvn installkhmarbaise
This was my first thought - but the error only occurs with my own plugin, not surefire. If the project was in someway incorrectly setup I'd expect both plugins to display the same error.henry
Did you read the description for @requiresDependencyCollection ? Maybe you are too early in the processing chain where actually the dependencies are not yet put onto the classpath?user1050755
Have you cleaned your local repository and tried to build the project from scratch without your plugin?khmarbaise
@khmarbaise Thanks for the suggestion but that wasn't it - just added an answer describing how this was resolved.henry

1 Answers

0
votes

For the benefit of anyone else having this issue - I eventually solved this problem. There was no issue with the plugin.

The difference between surefire and my own plugin was simply the way in which they were being run. Surefire was bound to the test phase, my own plugin was being run by calling a goal directly. When I bind my plugin to the verify phase, everything resolves without issue.