Maven的程序集插件可以创建一个大jar,包括所有与descriptorRef jar-with-dependencies
的依赖关系。
如何排除某些依赖关系?好像它没有这样的配置?还有其他解决方案吗?
答案 0 :(得分:21)
将<scope>provided</scope>
添加到您不希望包含在jar-with-dependencies中的依赖项,例如
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.6.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
答案 1 :(得分:11)
此example表示执行此操作的一种方法:
<dependencySets>
<dependencySet>
....
<excludes>
<exclude>commons-lang:commons-lang</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
</dependencySet>
....
</dependencySets>
基本上我们会使用excludes
中提供的dependencySet
选项。
另请参阅:https://maven.apache.org/plugins/maven-assembly-plugin/assembly-component.html
答案 2 :(得分:8)
您应该使用excludes
中提供的dependencySet
选项。
请按照以下说明:
pom.xml 中的示例:
...
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<finalName>../final/${project.artifactId}</finalName>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<mainClass>com.entrerprise.App</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/jar-with-deps-with-exclude.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
现在在新文件中 jar-with-deps-with-exclude.xml (其中 dependencySet 直播):
<?xml version="1.0" encoding="UTF-8"?>
<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>jar-with-dependencies-and-exclude-classes</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>junit:junit</exclude>
<exclude>commons-cli:commons-cli</exclude>
<exclude>org.apache.maven.wagon:wagon-ssh</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>
这就是全部。