maven-dependency-plugin、copy-dependency:排除一些工件 ID 及其依赖项

发布于 2024-10-15 06:48:28 字数 132 浏览 2 评论 0原文

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

有办法做到这一点吗?

I need to copy just one dependency and all its transitive dependencies to a specified folder.
I know i can exclude artifacts with "excludeArtifactIds", but I also need to exclude the transitive dependencies of those artifacts, which, apparently "excludeArtifactIds" does not do.

Is there a way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗笺 2024-10-22 06:48:28

看来 Maven 依赖插件不是为此设计的,因为它们关闭了 对此功能的一个请求为“WONTFIX”,另一请求 自 2007 年以来一直开放。

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

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

本质上,这将复制第一个项目,并且它是第二个项目的 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(聚合项目):

<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/pom.xml 程序集描述符:/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>

It appears that the Maven dependency plugin is not designed for this as they closed one request for this functionality as "WONTFIX" and another request has been OPEN since 2007.

However, you can use the maven-assembly-plugin to accomplish a similar task.

Below I've attached two sample POM's. The first is the dependent project (the one you wanted to copy) which itself has one dependency (for example). The second is the aggregate project where you are copying the other project and it's dependency to. I've also attached the assembly desriptor file that you'll use to copy the dependency.

Essentially, this will copy the first project and it's one dependency to the target/dest (configurable) directory of the second project.

First POM (dependent project): /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>

Second POM (aggregating project): /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>

Assembly descriptor : /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>
黑寡妇 2024-10-22 06:48:28

如何将 excludeTransitive 设置为 真?

How about setting excludeTransitive to true?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文