Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2
-
Fix Version/s: None
-
Component/s: java
-
Labels:None
-
Environment:Mac OS X, maven 2 and 3
-
Number of attachments :
Description
There is a bad interaction between the exec:java plugin and test-jar dependencies in a multi-module project. In short, if you attach exec:java to an execution phase, "mvn compile" then looks for "test-jar" dependencies even though it should only be looking for compile time dependencies.
Here is the setup:
/pom.xml
/cleartk-token/pom.xml
/cleartk-token/src/main/java/Token.java
/cleartk-token/src/test/java/TokenTest.java
/cleartk-named-entity/pom.xml
The cleartk-token module uses the "maven-jar-plugin" to package a "test-jar" dependency.
The cleartk-named-entity module depends on the cleartk-token "jar" dependency at compile time and (additionally) the cleartk-token "test-jar" dependency at test-compile time.
The cleartk-named-entity module uses exec:java to generate some code in the process-resources phase. (It doesn't actually call any main class in the attached file, but that doesn't seem to be necessary to provoke the bug.)
Given this setup, if you run "mvn compile" from the top level, with maven 2 you'll get the error:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) org.cleartk:cleartk-token:test-jar:tests:0.7.0-SNAPSHOT
And with maven 3 you'll get the error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal on project cleartk-named-entity: Could not resolve dependencies for project org.cleartk:cleartk-named-entity:jar:0.1.0-SNAPSHOT: Could not find artifact org.cleartk:cleartk-token:jar:tests:0.7.0-SNAPSHOT
Now this seems wrong in both cases - at compile time, maven shouldn't be looking for test jars.
I believe this is an exec:java bug (or at least exec:java revealing a compiler plugin bug) because if I comment out the <executions> element for the "maven-exec-plugin", then everything compiles fine.
My current workaround is to use "mvn compile package" which I guess makes the "test-jar" dependency visible at compile time. But since the "test-jar" dependency is a test-compile time dependency, I think this shouldn't be necessary.
Looks like this problem is bigger than just the exec plugin. Here's an even simpler setup that provokes the error:
/pom.xml
/module-with-test-jar/pom.xml
/module-needing-test-jar/pom.xml
If you use maven 3 to run:
You'll get the error:
[ERROR] Failed to execute goal on project module-needing-test-jar: Could not resolve dependencies for project bug:module-needing-test-jar:jar:0.0.1-SNAPSHOT: Could not find artifact bug:module-with-test-jar:jar:tests:0.0.1-SNAPSHOT
Which is wrong because you're in the compile phase and maven should not be looking for test scoped dependencies.
The key points are that the parent has two modules:
The first module supplies the test jar:
And the second module both depends on the test jar, and adds something to the compile phase (or earlier) using an <execution>:
Here I'm using maven-surefire-plugin to prove that it's not just the maven-exec-plugin that has this problem. In the attached code there's also a commented out section using the maven-exec-plugin that will provoke exactly the same bug.
Again, a workaround is to run mvn compile test-compile.