2011-06-02 1573 views

回答

11

example表示一種方法來做到這一點。

基本上我們會使用dependencySet中的excludes選項,如here所記錄的。

+4

這給出了一個錯誤:「無法識別的標記:'dependencySets'」for maven3 – zengr 2015-08-24 17:59:30

+4

這個例子假定我知道dependencySets在pom.xml中的位置。一個完整的例子會有幫助。 – 2017-03-22 16:42:34

+0

該鏈接不再工作 – 2017-10-12 06:36:23

12

<scope>provided</scope>添加到您不希望包含在jar -with-dependencies中的依賴項中,例如,

<dependency> 
     <groupId>storm</groupId> 
     <artifactId>storm</artifactId> 
     <version>0.6.1-SNAPSHOT</version> 
     <scope>provided</scope> 
    </dependency> 
+0

儘管如此,這仍然會包含傳遞依賴關係... – schneida 2016-06-13 13:24:56

1

您應該使用在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> 

就這樣。

相關問題