Maven 2 & 3

Multi-Module Project: module that depends on sibling test jar cannot execute test-compile without install of sibling first

Details

  • Complexity:
    Intermediate
  • Testcase included:
    yes
  • Number of attachments :
    4

Description

We have project with a few sibling modules:

  • Project
    ----moduleA
    +-- /src/main/java (Common Code)
    +-- /src/test/java (Common Test Framework)
    ----moduleB
    ----moduleC
    +-- /src/main/java (Production Code, depends on moduleA Common code)
    +-- /src/test/java (Production Test Framework, depends on moduleA Common Test Framework)

I dont think there is anything wrong with this project in concept. moduleC's "main" code depends son moduleA's "main" code, and moduleC's test code depends on moduleA's test code.

This works if I run 'mvn install', but for rapid development, we often run single unit tests and need to be able to run "mvn test" from the top level project, which fails.

For an example, download the attached project and run "mvn test" from the trunk directory. It will fail with the error pasted below. Then, run "mvn install" and everything works ok. We should be able to run our unit tests without having to install first.

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) com.kiva.demoPom:moduleA:test-jar:tests:0.0.1-SNAPSHOT

Try downloading the file manually from the project website.

Then, install it using the command:
mvn install:install-file -DgroupId=com.kiva.demoPom -DartifactId=moduleA -Dversion=0.0.1-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=com.kiva.demoPom -DartifactId=moduleA -Dversion=0.0.1-SNAPSHOT -Dclassifier=tests -Dpackaging=test-jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Path to dependency:
1) com.kiva.demoPom:moduleC:jar:0.0.1-SNAPSHOT
2) com.kiva.demoPom:moduleA:test-jar:tests:0.0.1-SNAPSHOT

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

for artifact:
com.kiva.demoPom:moduleC:jar:0.0.1-SNAPSHOT

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

  1. ActiveProjectTestJar-2.0.9.patch
    30/Apr/08 9:10 AM
    2 kB
    Joshua Pollak
  2. ActiveProjectTestJar-r2-2.0.9.patch
    30/Apr/08 7:01 PM
    3 kB
    Joshua Pollak
  3. demoPom.tgz
    29/Apr/08 4:17 PM
    68 kB
    Joshua Pollak
  4. demoPom-0.0.2-src.tgz
    30/Apr/08 7:04 PM
    68 kB
    Joshua Pollak

Issue Links

Activity

Hide
Joshua Pollak added a comment -

Here is a patch I think fixes the problem. The patch is against 2.0.9.

The problem turns out to be that MavenProject.replaceWithActiveArtifact() doesn't recognize the "test-jar" dependency as a active project artifact because moduleA's packaging is "jar", not "test-jar" (obviously). What I've done is added a specific case to check if the dependency is of type test-jar and the scope of the dependency is "test". If so, the patch creates and ActiveProjectArtifact() and replaces the File inside with:

new File(ref.getModelBuild().getTestOutputDirectory())

This doesn't allow production code to depend on another modules test's, but it does allow sibling tests to depend on another modules tests.

Show
Joshua Pollak added a comment - Here is a patch I think fixes the problem. The patch is against 2.0.9. The problem turns out to be that MavenProject.replaceWithActiveArtifact() doesn't recognize the "test-jar" dependency as a active project artifact because moduleA's packaging is "jar", not "test-jar" (obviously). What I've done is added a specific case to check if the dependency is of type test-jar and the scope of the dependency is "test". If so, the patch creates and ActiveProjectArtifact() and replaces the File inside with: new File(ref.getModelBuild().getTestOutputDirectory()) This doesn't allow production code to depend on another modules test's, but it does allow sibling tests to depend on another modules tests.
Hide
Joshua Pollak added a comment - - edited

The previous patch prevented the moduleC's production code from depending on moduleA's production code. This patch corrects this problem and replaces (obsoletes) the previous patch.

Show
Joshua Pollak added a comment - - edited The previous patch prevented the moduleC's production code from depending on moduleA's production code. This patch corrects this problem and replaces (obsoletes) the previous patch.
Hide
Joshua Pollak added a comment -

This updated demo project demonstrates the problem the -r2 patch corrects, and replaces the previously uploaded demoPom project.

Show
Joshua Pollak added a comment - This updated demo project demonstrates the problem the -r2 patch corrects, and replaces the previously uploaded demoPom project.

People

Vote (15)
Watch (18)

Dates

  • Created:
    Updated: