Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to divide artifacts between test and compile using the maven-dependency-plugin during the copy-dependencies goal?

I have the following configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.6</version>
  <executions>
      <execution>
          <id>analyze</id>
          <goals>
              <goal>analyze-only</goal>
          </goals>
          <configuration>
              <failOnWarning>false</failOnWarning>
          </configuration>
      </execution>
      <!--Copy the dependencies so ant build has the same versions-->
      <execution>
          <id>copy-dependencies</id>
          <phase>package</phase>
          <goals>
              <goal>copy-dependencies</goal>
          </goals>
          <configuration>
              <outputDirectory>${project.basedir}/lib</outputDirectory>
              <overWriteIfNewer>true</overWriteIfNewer>
              <stripVersion>true</stripVersion>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
              <excludeTransitive>false</excludeTransitive>
          </configuration>
      </execution>
  </executions>
</plugin>

The above configuration dumps everything on the same folder. I tried excluding the test scope by adding the test configuration but gives an error:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.6:copy-dependencies (copy-dependencies) on project pcgen: Can't exclude Test scope, this will exclude everything.

Is there a way to separate test dependencies from the rest so I can copy to different folders?

like image 552
javydreamercsw Avatar asked Dec 05 '12 15:12

javydreamercsw


People also ask

Which Maven phase copy a project artifact in the local repository for use as a dependency?

The dependency:copy goal can also be used to copy the just built artifact to a custom location if desired. It must be bound to any phase after the package phase so that the artifact exists in the repository.

What does Maven dependency plugin do?

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

What is the difference between dependency and plugin in Maven?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.

Are Maven dependencies compiled?

Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath.


1 Answers

I tried excluding the test scope by adding the test configuration but gives an error

I just stumbled across this, probably for very different reasons, but I think I found us both the answer. Try this, for example. You'll need pom.xml in the current directory, of course.

mvn dependency:copy-dependencies \
-DincludeScope=runtime \
-DexcludeScope=provided \
-DoutputDirectory=target/war/WEB-INF/lib

A huge belated thanks to Brian Fox, who writes on Maven Dependency Plugin Issue #128:

You shouldn't ever need to include or exclude two scopes at the same time because they are comprised of each other. The default is to include test scope, which includes everything. If you don't want any test dependencies or provided dependencies, then include runtime and exclude provided.

The scopes being interpreted are the scopes as maven sees them, not as specified in the pom. So the "test" scope includes everything, runtime includes compile but not provided etc.

In May 2013, the includeScope documentation was updated to:

/**
  * Scope to include. An Empty string indicates all scopes (default).
  * The scopes being interpreted are the scopes as
  * Maven sees them, not as specified in the pom. In summary:
  * <ul>
  * <li><code>runtime</code> scope gives runtime and compile dependencies,</li>
  * <li><code>compile</code> scope gives compile, provided, and system dependencies,</li>
  * <li><code>test</code> (default) scope gives all dependencies,</li>
  * <li><code>provided</code> scope just gives provided dependencies,</li>
  * <li><code>system</code> scope just gives system dependencies.</li>
  * </ul>
  * 
  * @since 2.0
  */
 @Parameter( property = "includeScope", defaultValue = "" )
 protected String includeScope;
like image 169
David J. Avatar answered Nov 12 '22 20:11

David J.