cal*_*014 7 maven-2 maven-dependency-plugin
我只需要将一个依赖项及其所有传递依赖项复制到指定的文件夹.我知道我可以用"excludeArtifactIds"排除工件,但我还需要排除那些工件的传递依赖性,显然"excludeArtifactIds"不能.
有办法做到这一点吗?
似乎Maven依赖插件不是为此而设计的,因为它们将此功能的一个请求关闭为"WONTFIX",另一个请求自2007年以来一直处于打开状态.
但是,您可以使用maven-assembly-plugin来完成类似的任务.
下面我附上了两个样本POM.第一个是依赖项目(您想要复制的项目),它本身具有一个依赖项(例如).第二个是聚合另一个项目的聚合项目,它依赖于.我还附加了用于复制依赖项的程序集desriptor文件.
从本质上讲,这将复制第一个项目,它是第二个项目的目标/ dest(可配置)目录的一个依赖项.
第一个POM(依赖项目):/ samples-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>
Run Code Online (Sandbox Code Playgroud)
第二个POM(聚合项目):/ samples-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>
Run Code Online (Sandbox Code Playgroud)
程序集描述符:/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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6018 次 |
| 最近记录: |