Scott Kurz opened MNG-8479 and commented
Recreate steps
With either a recent version of 3.9.x or 4.0.0-x, build my recreate plugin and use the j2ee-simple archetype to create a test project then run the test goal like this:
- git clone git@github.com:scottkurz/counter-maven-plugin.git; cd counter-maven-plugin; mvn install
- mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-j2ee-simple -DarchetypeVersion=1.5 -DgroupId=mygroup -DartifactId=myartifact -Dversion=1.0-SNAPSHOT -Dpackage=myco
- cd myartifact;
mvn mygroup:counter-maven-plugin:1.0-SNAPSHOT:countTargets
You'll see an artifact resolution failure like this:
[ERROR] Failed to execute goal on project ear: Could not resolve dependencies for project mygroup:ear:ear:1.0-SNAPSHOT
[ERROR] dependency: mygroup:ejbs:jar:1.0-SNAPSHOT (compile)
[ERROR] : The following artifacts could not be resolved: mygroup:ejbs:jar:1.0-SNAPSHOT (absent)
More Details
I was able to fix the issue by making this simple change to ReactorReader.java
#2016
Note my recreate/test plugin mojo looks like
@Mojo( name = "countTargets", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresDependencyResolution = ResolutionScope.TEST )
@Execute(phase = LifecyclePhase.PROCESS_TEST_CLASSES)
public class MyMojo
If I understand correctly, the role of the @Execute here is not to directly resolve the artifact (since this other stuff, IIUC, happens in a forked Maven)... but rather to enable the test in org.apache.maven.ReactorReader.find(MavenProject, Artifact) to pass (the test we use to decide whether to employ this special technique of resolving the artifact to the project output dir):
if ( project.hasLifecyclePhase( "compile" ) && COMPILE_PHASE_TYPES.contains( type ) )
I'm not really sure where the list of "types" from ReactorReader comes from:
privatestaticfinal Collection<String> COMPILE_PHASE_TYPES = new HashSet<>(
Arrays.asList("jar", "ejb-client", "war", "rar", "ejb3", "par", "sar", "wsr", "har", "app-client"));
It seems there's some overlap with packaging types but also that this is possibly a slightly different layer of abstraction?
I wonder though if these types though should align with the types here:
https://github.com/apache/maven/blob/master/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/type/DefaultTypeProvider.java
e.g.
new DefaultType("ejb", Language.JAVA_FAMILY, "jar", null, false, JavaPathType.CLASSES),
new DefaultType("ejb-client", Language.JAVA_FAMILY, "jar", "client", false, JavaPathType.CLASSES),
That's just a guess grepping through code..haven't traced it through.
Workarounds
I can avoid the problem either by:
- Adding a compile:
mvn compile mygroup:counter-maven-plugin:1.0-SNAPSHOT:countTargets
- Running a similar sample switching from an 'ejb' package type dependency to a regular 'jar' package
References
Affects: 3.9.6, 4.0.0-rc-2
Remote Links:
Backported to: 4.0.0-rc-3
Scott Kurz opened MNG-8479 and commented
Recreate steps
With either a recent version of 3.9.x or 4.0.0-x, build my recreate plugin and use the j2ee-simple archetype to create a test project then run the test goal like this:
mvn mygroup:counter-maven-plugin:1.0-SNAPSHOT:countTargetsYou'll see an artifact resolution failure like this:
[ERROR] Failed to execute goal on project ear: Could not resolve dependencies for project mygroup:ear:ear:1.0-SNAPSHOT[ERROR] dependency: mygroup:ejbs:jar:1.0-SNAPSHOT (compile)[ERROR] : The following artifacts could not be resolved: mygroup:ejbs:jar:1.0-SNAPSHOT (absent)More Details
I was able to fix the issue by making this simple change to ReactorReader.java
#2016
Note my recreate/test plugin mojo looks like
If I understand correctly, the role of the
@Executehere is not to directly resolve the artifact (since this other stuff, IIUC, happens in a forked Maven)... but rather to enable the test in org.apache.maven.ReactorReader.find(MavenProject, Artifact) to pass (the test we use to decide whether to employ this special technique of resolving the artifact to the project output dir):I'm not really sure where the list of "types" from ReactorReader comes from:
It seems there's some overlap with packaging types but also that this is possibly a slightly different layer of abstraction?
I wonder though if these types though should align with the types here:
https://github.com/apache/maven/blob/master/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/type/DefaultTypeProvider.java
e.g.
That's just a guess grepping through code..haven't traced it through.
Workarounds
I can avoid the problem either by:
mvn compile mygroup:counter-maven-plugin:1.0-SNAPSHOT:countTargetsReferences
Affects: 3.9.6, 4.0.0-rc-2
Remote Links:
Backported to: 4.0.0-rc-3