Maven-将特定依赖项及其可传递依赖项复制到给定位置
我有一个maven项目,我说spring框架库是依赖项,我想将具有可传递依赖项的spring框架依赖项复制到指定的位置 我已经阅读了apache的maven依赖插件指南,我有几个选项,其中没有一个可以解决完整的问题Maven-将特定依赖项及其可传递依赖项复制到给定位置,maven,dependency-management,Maven,Dependency Management,我有一个maven项目,我说spring框架库是依赖项,我想将具有可传递依赖项的spring框架依赖项复制到指定的位置 我已经阅读了apache的maven依赖插件指南,我有几个选项,其中没有一个可以解决完整的问题 复制依赖项选项 org.apache.maven.plugins maven依赖插件 2.8 复制依赖项 包裹 复制依赖项 ${project.build.directory}/alternateLocation 假的 假的 真的 这将把所有的依赖项和转换项复制到一个给定的位置,
org.apache.maven.plugins
maven依赖插件
2.8
复制依赖项
包裹
复制依赖项
${project.build.directory}/alternateLocation
假的
假的
真的
这将把所有的依赖项和转换项复制到一个给定的位置,我只想要spring依赖项和转换项
org.apache.maven.plugins
maven依赖插件
2.8
复制
包裹
复制
org.springframework
弹簧网
3.2.4.1发布
罐子
false${project.build.directory}/alternateLocation
可选-new-name.jar
${project.build.directory}/wars
假的
真的
这不是处理可传递依赖项
任何解决我这两个问题的办法 您可以使用maven assembly插件进行此操作 查看它,特别是依赖项集: 您可以提供一个输出目录,并指定要放入其中的依赖项 还有一个选项:
useTransitiveDependencies
。将此设置为true以获得所需的行为。这里有一个选项:
- 创建模块(producer)以收集依赖项并将它们作为zip文件发布
- 在消费者用户依赖中:解包以解包该拉链
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>packaging</groupId>
<artifactId>jdbcdrivers</artifactId>
<packaging>zip</packaging>
<name>jdbcdrivers</name>
<dependencies>
<!-- set up deps for capture and limit their impact on anything which depends upon this module via optional-false -->
<dependency>
<groupId>net.sf.jtds</groupId>
<artifactId>jtds</artifactId>
<scope>test</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<scope>test</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
<optional>false</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>dist profile: hive jdbc driver ${baseName}</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/lib/addons/jdbcdriver/</outputDirectory>
<useBaseVersion>true</useBaseVersion>
<excludeTransitive>false</excludeTransitive>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>test</includeScope>
<excludeScope>provided</excludeScope>
<excludeGroupIds>org.codehaus.groovy,org.apache.ivy,jdk.tools</excludeGroupIds> <!-- you might need to cherry pick excludes if scope doesn't worjk -->
<prependGroupId>true</prependGroupId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
包装
jdbc驱动程序
拉链
jdbc驱动程序
net.sf.jtds
jtds
测试
假的
org.apache.hive
蜂窝jdbc
测试
假的
postgresql
postgresql
测试
假的
org.apache.maven.plugins
maven汇编插件
org.apache.maven.plugins
maven antrun插件
org.apache.maven.plugins
maven依赖插件
dist配置文件:配置单元jdbc驱动程序${baseName}
准备包装
复制依赖项
${project.build.outputDirectory}/lib/addons/jdbcdriver/
真的
假的
真的
测试
假如
org.codehaus.groovy、org.apache.ivy、jdk.tools
真的
这可以通过汇编插件实现
插件配置:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>plugins</finalName> <!--folder name in target directory-->
</configuration>
<executions>
<execution>
<id>some-id</id> <!-- must match assembly id in assembly.xml-->
<phase>pre-integration-test</phase> <!-- pic -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
maven汇编插件
3.1.0
src/assembly/assembly.xml
插件
一些身份证
预集成测试
单一的
assembly.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>some-id</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>
org.springframework:spring-web
</include>
</includes>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
</dependencySets>
</assembly>
一些身份证
迪尔
假的
springframework:springweb
真的
真的
重要的位是
true
和true
,这导致包含应用于项目依赖项,但不应用于可传递依赖项,导致spring web工件及其依赖项被复制到目录。使用目标而不是复制目标可能更好。-1因为maven汇编插件在这方面的行为完全相同。当像op建议的那样在dependencySet
中只包含org.springframework:spring web
工件时,不管设置UseTrantiveDependencies
,都只会复制它,因为它的所有可传递依赖项都不包括在白名单中。这真烦人,我感觉到你的痛苦。我认为唯一可行的方法是创建一个子项目或另一个模块,这取决于您想要的项目,然后让它生成一个包含其deps+可传递项的zip。这应该是现成的吗?我得到了未知的包装:zip,我想是的。这是有可能的,因为我尝试了两年后,这个maven取消了zip。Zip不保留权限,因此不如tar好(当涉及java时,tar也不一定保留权限)
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>plugins</finalName> <!--folder name in target directory-->
</configuration>
<executions>
<execution>
<id>some-id</id> <!-- must match assembly id in assembly.xml-->
<phase>pre-integration-test</phase> <!-- pic -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>some-id</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>
org.springframework:spring-web
</include>
</includes>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
</dependencySets>
</assembly>