我有以下配置:

<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>


上面的配置将所有内容转储到同一文件夹中。我尝试通过添加测试配置来排除测试范围,但出现错误:


无法在项目pcgen上执行目标org.apache.maven.plugins:maven-dependency-plugin:2.6:copy-dependencies(复制依赖项):无法排除测试范围,这将排除所有内容。


有没有一种方法可以将测试依赖项与其他依赖项分开,以便我可以复制到其他文件夹?

最佳答案

我尝试通过添加测试配置来排除测试范围,但给出了错误

我偶然发现了这个问题,可能是由于非常不同的原因,但是我想我找到了答案。例如,尝试一下。当然,您将在当前目录中需要pom.xml。

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

非常感谢Brian Fox在Maven Dependency Plugin Issue #128上写道:

您永远不需要同时包含或排除两个范围,因为它们是相互组成的。默认值是包括测试范围,其中包括所有内容。如果您不需要任何测试依赖项或提供的依赖项,请包括运行时并排除提供的项。
被解释的作用域是Maven看到的作用域,而不是pom中指定的作用域。因此,“测试”范围包括所有内容,运行时包括编译但未提供等。

2013年5月,includeScope documentation was updated可以:
/**
  * 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;

09-10 01:04
查看更多