Maven的程序集插件允許創建一個大的jar包括所有與descriptorRef jar-with-dependencies
之間的依賴關係。如何從Maven Assembly插件中排除依賴關係:jar-with-dependencies?
如何排除一些這些依賴關係?它似乎沒有這樣的配置?還有其他解決方案嗎?
Maven的程序集插件允許創建一個大的jar包括所有與descriptorRef jar-with-dependencies
之間的依賴關係。如何從Maven Assembly插件中排除依賴關係:jar-with-dependencies?
如何排除一些這些依賴關係?它似乎沒有這樣的配置?還有其他解決方案嗎?
將<scope>provided</scope>
添加到您不希望包含在jar -with-dependencies中的依賴項中,例如,
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.6.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
儘管如此,這仍然會包含傳遞依賴關係... – schneida 2016-06-13 13:24:56
您應該使用在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-與-DEPS與 - 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>
<outputDirectory>/</outputDirectory>
<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>
就這樣。
這給出了一個錯誤:「無法識別的標記:'dependencySets'」for maven3 – zengr 2015-08-24 17:59:30
這個例子假定我知道dependencySets在pom.xml中的位置。一個完整的例子會有幫助。 – 2017-03-22 16:42:34
該鏈接不再工作 – 2017-10-12 06:36:23