我需要将一个依赖项及其所有传递依赖项复制到指定的文件夹。 我知道我可以使用“excludeArtifactIds”排除工件,但我还需要排除那些工件的传递依赖关系,显然“excludeArtifactIds”不会这样做。
有没有办法做到这一点?
答案 0 :(得分:7)
Maven依赖插件似乎是而不是为此设计的,因为他们关闭此功能的one request为“WONTFIX”,another request自2007年以来一直处于打开状态。< / p>
但是,您可以使用maven-assembly-plugin来完成类似的任务。
下面我附上了两个样本POM。第一个是依赖项目(您想要复制的项目),它本身具有一个依赖项(例如)。第二个是聚合另一个项目的聚合项目,它依赖于。我还附加了用于复制依赖项的程序集desriptor文件。
基本上,这将复制第一个项目,并且它是第二个项目的target / dest(可配置)目录的一个依赖项。
第一个POM(依赖项目):/ sample-dependency/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sample-dependency</groupId>
<artifactId>sample-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
第二个POM(聚合项目):/ sample-dependency-aggregator/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sample-dependency-aggregator</groupId>
<artifactId>sample-dependency-aggregator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sample-dependency-aggregator</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>aggregate</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/default.xml</descriptor>
</configuration>
</execution>
</executions>
<configuration>
<attach>false</attach>
<finalName>dest</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>sample-dependency</groupId>
<artifactId>sample-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
汇编描述符:/sample-dependency-aggregator/src/main/assembly/default.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd ">
<id>default</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<include>sample-dependency:sample-dependency</include>
</includes>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
</dependencySets>
</assembly>
答案 1 :(得分:1)
如何将excludeTransitive设为true
?