Isu*_*uru 9 dependency-management maven
我有一个maven项目,我说Spring框架库作为依赖项,我想将spring框架依赖项与传递依赖项复制到指定的位置.
我已经浏览了apache的maven依赖插件指南,我有几个选项,其中没有它们将解决完整的问题.
Run Code Online (Sandbox Code Playgroud)<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin>
这将复制所有依赖项和传递到给定位置,我只需要Spring依赖项和传递.
Run Code Online (Sandbox Code Playgroud)<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.2.4.RELEASE</version> <type>jar</type> <overWrite>false</overWrite> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <destFileName>optional-new-name.jar</destFileName> </artifactItem> </artifactItems> <outputDirectory>${project.build.directory}/wars</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> </configuration> </execution> </executions> </plugin>
这不是应对传递依赖.
解决我的两个问题的任何解决方案.
程序集插件可以做到这一点。
插件配置:
<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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
重要的位是<useTransitiveDependencies>true</useTransitiveDependencies>和<useTransitiveFiltering>true</useTransitiveFiltering>,这将导致include将应用于项目依赖项,而不应用于传递性依赖项,从而导致spring-web工件及其依赖项被复制到目录中。
您可以为此使用 Maven 程序集插件。
检查一下,特别是依赖项集:
http://maven.apache.org/plugins/maven- assembly-plugin/
http://maven.apache.org/plugins/maven- assembly-plugin/ assembly.html#class_dependencySet
您可以提供一个输出目录,并可以指定要放入其中的依赖项
还有一个选项:useTransitiveDependencies。将其设置为 true 以获得您想要的行为。
| 归档时间: |
|
| 查看次数: |
5392 次 |
| 最近记录: |