Issue Details (XML | Word | Printable)

Key: MNG-2045
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Brian Fox
Reporter: Brian Fox
Votes: 11
Watchers: 13
Operations

If you were logged in you would be able to see more operations.
Maven 2 & 3

Maven can't compile against sibling test-jar dependency in multiproject (Test Attached)

Created: 06/Feb/06 03:51 PM   Updated: 28/Oct/09 01:48 PM   Resolved: 27/Feb/09 08:20 AM
Return to search
Component/s: None
Affects Version/s: 2.0.2
Fix Version/s: 2.0.8

Time Tracking:
Not Specified

File Attachments: 1. GZip Archive it1021.tar.gz (1 kB)
2. Zip Archive mng-2045-ittest.zip (10 kB)
3. File MNG-2045-maven-project-r577340.patch1 (0.8 kB)
4. File MNG-2045-maven-project-r577340.patch2 (1 kB)
5. Zip Archive sample.zip (23 kB)

Environment: WinXP
Issue Links:
Related
Supercedes
 
dependent
 

Complexity: Intermediate
Testcase included: yes


 Description  « Hide

I have 2 projects under a parent like so:

--Parent
— sample-jar
— sample-jar-user

sample-jar builds and installs a test-jar along with the normal jar. sample-jar-user depends on the test-jar at compile time. When I build from the parent folder, the build fails because it can't find the class. When I go to sample-jar-user and build, it works fine.

In the attached test case, to reproduce:
from the root folder, run mvn clean install - See it fail.
cd sample-jar-user; mvn clean install - see it succeed.

I remember reading somewhere that in multiprojects, maven attempts to locate the sibling classes in the source tree instead of using the jars from the repository. I'm guessing the problem is here that it's not looking in ../sample-jar/target/test-classes for this code, but really one should expect this to come from the repository.



Carlos Sanchez added a comment - 06/Feb/06 05:03 PM

Integration test.
If classes are moved to test folder and dependency set as test scope it works fine, using the jar from repo
If trying to use in compile scope it references ../child1/target/classes twice in the compiler classpath


Carlos Sanchez added a comment - 06/Feb/06 05:05 PM

Brian, it works if you use test-jar in a test scope, which is the usual case. Your main classes shuldn't depend on test classes from other modules


Brian Fox added a comment - 06/Feb/06 05:15 PM

Yes, I realize this is an unusual case. The code is something we are working to fix, but it was working until I moved it into a common parent in preparation for some other stuff. It seems by extension this would be a problem for other dependencies that use classifiers.


Brian Fox added a comment - 28/Feb/06 10:10 PM

I believe this is related to MWAR-7 and MOJO-286


Archimedes Trajano added a comment - 26/Feb/07 01:34 PM

We have the normal case, but it won't work unless we before an install first.


Archimedes Trajano added a comment - 26/Feb/07 01:36 PM

We have the normal case, but it won't work unless we do an install first.

So mvn clean install on the project will run the tests correctly.
But mvn clean test won't because the test-jar dependency won't resolve.


Brian Fox added a comment - 10/Apr/07 07:42 PM

Tested with 2.0.6, this no longer occurs. It's fixed by MNG-2877


Stefan Magnus Landrø added a comment - 10/Jul/07 06:44 AM

This issue still occurs for me. Tested with maven 2.0.6 and 2.0.7. I still have to run a install first.


Mikko Koponen added a comment - 17/Sep/07 07:22 AM - edited

We're also running into this problem, which is that:

  • We have project A with common test classes in src/main/test
  • Project A creates a test jar
  • Project B depends on project A's test jar in compile scope
  • Project B builds fine if built on it's own, but fails when in a reactor build with project A.

I know we shouldn't have a dependency from the main code of B to a test artifact of project A, but it would make my job considerably easier if this "just worked", or even if it also failed when only building project B.


Brian Fox added a comment - 17/Sep/07 09:50 AM

This should be fixed. If you can reproduce, please make an IT test and attach. Instructions for an IT are here: http://docs.codehaus.org/display/MAVEN/Creating+a+Maven+Integration+Test


Mikko Koponen added a comment - 18/Sep/07 04:18 AM - edited

Attaching mng-2045-ittest.zip, which contains an integration test reproducing the problem. Well, at least "on-my-machine" anyway.

Tested with maven 2.0.7.


Brian Fox added a comment - 18/Sep/07 08:47 AM

will try out the IT, thanks.


Paul Gier added a comment - 19/Sep/07 11:44 AM

I'm having the same issue where we have one module whose main classes depend on test classes from another module. I'm attaching a simple fix for this where the artifact type is checked (test-jar) when adding the path.


Paul Gier added a comment - 19/Sep/07 11:47 AM

This patch has a slight enhancement over the first one I submitted. The problem with the first, is that if "clean compile" is run in a multi-module project, then the test-classes directory does not exist. So this patch checks for the existence of the test output directory. And if it does not exist, it falls back to the repository.


Brian Fox added a comment - 16/Oct/07 07:50 PM

Patch and core it applied thanks to all that contributed. The IT test passes now.


Tomas Cirip added a comment - 19/Dec/07 11:44 AM

Brian,

I find both sample projects (it1021.tar.gz and sample.zip) not working in 2.0.8). Can you comment on this, please? Thanks

Tomas


Brett Porter added a comment - 26/Feb/08 02:09 PM

this was fixed in 2.0.8 - sample.zip, it1021.tar.gz and the integration all test with it.

Please open a new issue with more specifics if you are still seeing the problem.


Joshua Pollak added a comment - 29/Apr/08 05:57 PM

I don't think this bug is fixed.

If I download sample.zip and run 'mvn test-compile', I get the following:

jpollak@Challenger:~/src$ cd sample/
jpollak@Challenger:~/src/sample$ ls
pom.xml sample-jar sample-jar-user
jpollak@Challenger:~/src/sample$ mvn test-compile
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] Unnamed - sample-project:sample-parent:pom:SNAPSHOT
[INFO] Maven Quick Start Archetype
[INFO] Maven Quick Start Archetype
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - sample-project:sample-parent:pom:SNAPSHOT
[INFO] task-segment: [test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] No goals needed for project - skipping
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype
[INFO] task-segment: [test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype
[INFO] task-segment: [test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) sample-project:sample-jar:test-jar:tests:SNAPSHOT

Try downloading the file manually from the project website.

Then, install it using the command:
mvn install:install-file -DgroupId=sample-project -DartifactId=sample-jar -Dversion=SNAPSHOT -Dclassifier=tests -Dpackaging=test-jar -Dfile=/path/to/file

Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=sample-project -DartifactId=sample-jar -Dversion=SNAPSHOT -Dclassifier=tests -Dpackaging=test-jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Path to dependency:
1) sample-project:sample-jar-user:jar:SNAPSHOT
2) sample-project:sample-jar:test-jar:tests:SNAPSHOT

----------
1 required artifact is missing.

for artifact:
sample-project:sample-jar-user:jar:SNAPSHOT

from the specified remote repositories:
central (http://repo1.maven.org/maven2)

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Apr 29 18:55:27 EDT 2008
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------


Ceki Gulcu added a comment - 27/Oct/08 03:07 PM

I am seeing the same behavior with maven 2.0.9 when trying to build logback. See
http://svn.qos.ch/viewvc/logback/trunk/ if you would like to check out the project.

In this particular case, logback-classic depends on logback-core as follows:

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

For a pristine installation, 'mvn package' fails with

===================
Missing:
----------
1) ch.qos.logback:logback-core:jar:tests:0.9.10

Try downloading the file manually from the project website.
[snip]

Path to dependency:
1) ch.qos.logback:logback-classic:jar:0.9.10
2) ch.qos.logback:logback-core:jar:tests:0.9.10

===================

whereas 'mvn install' works fine.

The SLF4J project which I maintain suffers from the same problem. See http://svn.slf4j.org/repos/slf4j/trunk/ is you wish to check out SLF4J.


Joerg Schaible added a comment - 28/Oct/08 02:04 AM

For whatever it is worth, you may define the dependency as

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

at least such a declaration works in quite some of our projects.


Ceki Gulcu added a comment - 28/Oct/08 04:48 AM

Thank you Joerg. The change you suggested worked beautifully.


Benjamin Bentmann added a comment - 01/Nov/08 08:23 AM

The documentation has been fixed in r709688. Left to discussion is whether the <classifier>tests</classifier> approach should also be supported.


Brett Porter added a comment - 18/Dec/08 04:47 AM

could this be considered fixed in 2.0.10 and a new issue opened for the classifier approach?


Benjamin Bentmann added a comment - 27/Feb/09 08:20 AM

The issue that was originally reported here, i.e. a bad compile class path when depending on a test JAR and running the install phase of a reactor build, was fixed in 2.0.8. Other issues like only running the test phase (MNG-3043) or the proper way to declare a test JAR dependency (MNG-4056) are addressed by the referenced JIRA tickets.


Obi Ezechukwu added a comment - 21/Jul/09 04:47 AM

I have attemted Joerg's suggestion, and I am afraid that I am experiencing the same problem with maven 2.1.0. So it does not appear that this issue has been fixed for multi-module projects.