0

My situation is pretty much the same than the one exposed in this issue except that the proposed solution using -DincludeScope=runtime doesn't work for me :

  1. I build jar
  2. I want to copy the dependency in a folder for running the application. In this folder, I don't need the tests related classes/libraries.
  3. (but out of scope here) I build an archive file (.war) for deploying purpose. This archive does not contain the tests libraries.

My pom looks like :

<dependencies>
  <dependency>
    <groupId>my.company.group</groupId>
    <artifactId>common</artifactId>
    <version>4.0.0-SNAPSHOT</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>my.company.group</groupId>
    <artifactId>common</artifactId>
    <version>4.0.0-SNAPSHOT</version>
    <type>test-jar</type>
    <scope>test</scope>
  </dependency>
</dependencies>

As you may notice, we are using a common project providing generic classes for this project (among others). The issue has rise recently when putting generic test classes in this project and therefore creating the need of a second jar archive for test purpose. In my opinion, it should work like a charm : both jar files have different names and scope.

Creating a .war archive through mvn clean compile is fine : the created war archive does not contain the test lib.

But copying the dependencies with mvn clean compile dependency:copy-dependencies -DoutputDirectory=./libPath -DincludeScope=runtime jar:jar seems to not taking the scope into account. As pointed out in some other posts, the param -DexcludeScope=test is useless as it exclude every scope.

I also tried to use the classifier attribute on the dependency declaration and -DexcludeClassifiers=test when running maven without notable effect.

Is there something that I'm missing, either in my mave call or my pom config ?

(Fyi : maven version is 3.0.5, running on java 7)

Marc Lefèvre
  • 41
  • 1
  • 8

1 Answers1

0

Finally, after some more searches, the solution was in the correct understanding of a maven lifecycle.

Long story short : I've modified the maven call, not the pom config (using the test-compile phase before the compile one):

mvn clean test-compile dependency:copy-dependencies -DoutputDirectory=./libPath -includeScope=runtime compile jar:jar

Reading the maven documentation, the default build phases flow is the following :

  1. clean
  2. process-sources
  3. compile
  4. process-test-sources
  5. test-compile
  6. package

The goal dependency is default bound to the process-sources phase and in my first attempt I bound it to the compile phase. I think that my issue came from the fact that when this goal was executed, the test classes weren't compiled yet and thus not 'flagged' as such.

Running the test-compile phase before the compile one (and binding the copy goal on the former) allows the test classes to be recognized and therefore the value of the -DincludeScope parameter to be effectively used.

That being said, this is nearly pure empiric understanding. If someone has more theoretical explanation or documentation, I would gladly hear about it.

Marc Lefèvre
  • 41
  • 1
  • 8