Maven的组装插件支持创建一个大jar,其中包含descriptorRef jar-with-dependencies的所有依赖项。
如何排除其中的一些依赖关系?它似乎没有这样的配置?有没有其他的解决方案?
发布于 2011-06-02 12:49:55
此example指明了一种实现此目的的方法:
<dependencySets>
<dependencySet>
....
<excludes>
<exclude>commons-lang:commons-lang</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
</dependencySet>
....
</dependencySets>本质上,我们将使用dependencySet中提供的excludes选项。
另请参阅:https://maven.apache.org/plugins/maven-assembly-plugin/assembly-component.html
发布于 2015-03-29 21:28:06
将<scope>provided</scope>添加到不希望包含在带有依赖项的jar中的依赖项中,例如
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.6.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>发布于 2017-12-18 23:29:19
您应该使用dependencySet中提供的excludes选项。
如下所示:
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>就这样。
https://stackoverflow.com/questions/6209903
复制相似问题