gpt4 book ai didi

java - 具有可传递依赖项的 maven 程序集插件依赖项集

转载 作者:行者123 更新时间:2023-12-04 20:15:09 25 4
gpt4 key购买 nike

我不明白如何将部分依赖添加到 <dependencySet>组装中

例如,我依赖于 group:artifact1 和 group:artifact2,它们都依赖于 group:artifact0。

我创建的程序集描述符应该复制 group:artifact2 和所有依赖项。

如果在 pom.xml 中对 group:artifact1 的依赖出现在对 group:artifact2 的依赖之前,我在目标目录中只有 group:artifact2,但是如果我改变依赖关系的顺序,那么我在目标目录中有两个 Artifact 。

结果我想有两个包含不同库集的目录。

简单的例子在这里

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>com.kudrevatykh.stackoverflow</groupId>
<artifactId>assembly-question</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring.version>3.2.3.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>install.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

安装文件
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>install</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>org.springframework:spring-jdbc:jar</include>
</includes>
<useTransitiveFiltering>true</useTransitiveFiltering>
<outputDirectory>/</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
mvn --version输出
Apache Maven 3.0.4 (r1232337; 2012-01-17 12:44:56+0400)
Maven home: C:\Users\akudrevatykh\bin\apache-maven-3.0.4
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: C:\Users\akudrevatykh\bin\jdk1.7.0_11\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

最佳答案

您需要创建多个 dependencySet s,每个要创建的目录一个,然后使用 includesexcludes控制哪些依赖项进入哪个目录。

例如,如果您想要 spring-aopaop 结束目录和 spring-jdbcjdbc 结束目录,您将使用以下 dependencySet s:

<dependencySets>

<dependencySet>
<outputDirectory>aop</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>org.springframework:spring-aop:jar</include>
</includes>
</dependencySet>

<dependencySet>
<outputDirectory>jdbc</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>org.springframework:spring-jdbc:jar</include>
</includes>
</dependencySet>

</dependencySets>

您需要确保引入正确的传递依赖项,可能是通过添加额外的 include s,但你明白了要点。

关于java - 具有可传递依赖项的 maven 程序集插件依赖项集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22505886/

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