Maven 2 不包括「;“提供”;来自Maven程序集的依赖项
我试图使用Maven assembly插件构建一个包含依赖项的jar,但那些提供了作用域的jar除外 我已将带有依赖项的jar复制到assembly.xml文件中,并在pom中配置了它的使用。以下为参考:Maven 2 不包括「;“提供”;来自Maven程序集的依赖项,maven-2,maven-plugin,Maven 2,Maven Plugin,我试图使用Maven assembly插件构建一个包含依赖项的jar,但那些提供了作用域的jar除外 我已将带有依赖项的jar复制到assembly.xml文件中,并在pom中配置了它的使用。以下为参考: <?xml version="1.0" encoding="UTF-8"?> <assembly> <id>injectable-jar</id> <formats> <format>jar</for
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>injectable-jar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>
注射罐
罐子
假的
真的
运行时
${project.build.outputDirectory}
我发现,如果我将范围设置为提供的
,那么我可以构建一个包含我不想要的内容的jar,但我不知道如何获得相反的行为。这有点笨拙,但您可以使用maven依赖插件将所有依赖项复制/解包到您的项目中,然后使用汇编插件进行打包
copy dependencies
和unpack dependencies
目标都有一个可选属性,您可以将其设置为忽略提供的依赖项。下面的配置将所有依赖项复制到target/lib中,您的程序集插件描述符可以修改为使用包含这些jar的
更新:刚刚测试了这个以确认它的工作。添加了将程序集插件绑定到包阶段的配置,以及对程序集描述符的相关修改
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeScope>provided</excludeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
<execution>
<id>jar-with-deps</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/my-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
对于最新的Maven(我在Maven 3.0上进行测试),这似乎与预期一样有效,但有一些警告:
请求的作用域(在dependencySet中)可能包括基于以下定义的其他作用域:
因此,如果您请求编译范围,您将获得compile和provided。但是,如果您请求运行时范围,您应该获得compile和runtime(但未提供)。理论上,标记“ignoreNonCompile”和“excludeScope”应该会有所帮助,但请注意它们不一定能正常工作
对于maven 3和maven依赖插件2.4,一个解决方案是:
<configuration>
<excludeArtifactIds>junit,mockito-all</excludeArtifactIds>
<excludeTransitive>true</excludeTransitive>
</configuration>
朱尼特,莫基托
真的
这是一篇老文章,但是maven依赖插件现在有一个“excludeScope”选项,您可以将其设置为“提供”或任何您需要的范围
比如说,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven依赖插件
2.10
复制依赖项
准备包装
复制依赖项
${project.build.directory}/lib
假的
假的
真的
假如
作为示例显示的程序集的JAR包含哪些内容?它是否只包含运行时依赖项?它似乎包含除test
-作用域依赖项之外的所有内容。不,它还包含test
-作用域依赖项。我想知道,在什么情况下,这可能是一个正常的默认值?我不知道如何让它排除我所拥有的一个test
依赖项,但除此之外,它工作得非常完美。:)这甚至更麻烦,但如果您需要排除测试范围,您可以定义依赖插件的多个执行,并在每次执行中指定要包含的不同范围(即,为了省略测试并提供,定义两个执行,一个用于编译,一个用于运行时),结果证明一个执行就足够了<代码>运行时
是我所需要的全部-它隐式地排除了测试
、提供的
和系统
,这是完美的。如果提供的依赖同时也恰好属于运行时可传递的依赖,那么此功能是否正确地排除了它?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>