我已经创建了一个maven配置文件,其中包含maven-dependency-plugin。
下面是我的插件
<profile>
<id>copy-dep</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-external</id>
<phase>none</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeGroupIds>group ids that I need to exclude</excludeGroupIds>
<excludeArtifactIds>artifact ids that I need to exclude</excludeArtifactIds>
<includeArtifactIds>artifact ids that I need to include</includeArtifactIds>
<includeGroupIds>group id that I need to include</includeGroupIds>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
我使用下面的命令来执行
mvn dependency:copy-dependencies -DoutputDirectory=libs -Pcopy-dep
但是当我执行该命令时,它会查找pom中定义的所有依赖项,并复制它们。
我试着把不想要的依赖项放在exclude标签中,但没有起作用,然后我也试着删除exclude标签并保留所需的依赖项,但也不起作用。
在我的pom中,我使用maven汇编插件来分离出所需的依赖项,我不希望这些依赖项被复制到创建的配置文件中。
你知道我在哪里做错了吗?有没有更好的方法来达到同样的效果。
发布于 2020-06-17 19:59:03
为了只复制“列出的”工件(在本例中,它将只复制junit和mockito):
<profile>
<id>copy-dep</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</artifactItem>
<artifactItem>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
并执行它:
mvn dependency:copy -Pcopy-dep
发布于 2020-06-17 21:33:54
您需要告诉Maven运行哪个执行。所以写下:
mvn dependency:copy-dependencies@copy-external -DoutputDirectory=libs -Pcopy-dep
顺便说一句:把这个放到一个配置文件中可能没有必要。
https://stackoverflow.com/questions/62427577
复制相似问题