gpt4 book ai didi

maven-2 - Maven 依赖插件,复制依赖 : exclude some artifact ids and their dependencies

转载 作者:行者123 更新时间:2023-12-04 11:44:08 25 4
gpt4 key购买 nike

我只需要将一个依赖项及其所有传递依赖项复制到指定的文件夹中。
我知道我可以使用“excludeArtifactIds”排除工件,但我还需要排除这些工件的传递依赖项,显然“excludeArtifactIds”不会这样做。

有没有办法做到这一点?

最佳答案

看来Maven依赖插件是不是 专为此设计,因为他们关闭 one request将此功能称为“WONTFIX”和 another request自 2007 年开始营业。

但是,您可以使用 maven-assembly-plugin 来完成类似的任务。

下面我附上了两个示例 POM。第一个是依赖项目(您要复制的项目),它本身具有一个依赖项(例如)。第二个是聚合项目,您将在其中复制另一个项目及其依赖项。我还附上了您将用于复制依赖项的程序集描述 rune 件。

本质上,这将复制第一个项目,它是第二个项目的目标/目标(可配置)目录的一个依赖项。

第一个 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>

关于maven-2 - Maven 依赖插件,复制依赖 : exclude some artifact ids and their dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4853802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com