2017-10-09 79 views
0

當嘗試創建可分發的歸檔時,使用Maven程序集插件時出現問題。一切都是 工作正常,除了從歸檔lib目錄中缺少一些依賴關係罐。例如hamcrest-core.jar,xnio-nio-3.3.6.Final.jar,objenesis-2.5.jar以及其他幾個罐子都不添加。是否有任何理由不包括在內? maven-dependency-plugin包含了target/lib中的所有依賴jar,並且沒問題。Maven程序集插件依賴關係罐缺失

這裏是我有我的pom.xml

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>3.0.1</version> 
    <executions> 
     <execution> 
      <id>copy</id> 
      <phase>install</phase> 
      <goals> 
       <goal>copy-dependencies</goal> 
      </goals> 
      <configuration> 
       <outputDirectory> 
        ${project.build.directory}/lib 
       </outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <groupId>org.apache.maven.plugins</groupId> 
    <version>3.1.0</version> 
    <executions> 
     <execution> 
     <id>online-store</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     <configuration> 
      <archive> 
       <manifest> 
        <addClasspath>true</addClasspath> 
        <classpathPrefix>lib/</classpathPrefix> 
        <mainClass>com.online.store.Main</mainClass> 
       </manifest> 
      </archive> 
      <appendAssemblyId>false</appendAssemblyId> 
      <descriptors> 
       <descriptor>src/assembly/assembly.xml</descriptor> 
      </descriptors> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 

內,這裏是我在assembly.xml

<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>online-store</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets> 
     <!-- some file sets --> 
    </fileSets>  
    <dependencySets> 
     <dependencySet> 
     <scope>compile</scope> 
     <includes> 
        <include>*:jar:*</include> 
      </includes> 
     <outputDirectory>/online-store/lib</outputDirectory> 
    </dependencySet> 
    </dependencySets> 
</assembly> 
+0

?在彙編文件中,您指出只提供範圍 –

+0

它是範圍測試。我怎樣才能改變範圍也包括他們? –

+0

您可以包含另一個依賴項集,其範圍測試 –

回答

0

可以包括另一dependencySet與範圍的測試。

例如:

哪個範圍都依賴不包含
<assembly> 
    ... 
    <dependencySets> 
     <dependencySet> 
     <scope>compile</scope> 
     <includes> 
       <include>*:jar:*</include> 
      </includes> 
     <outputDirectory>/online-store/lib</outputDirectory> 
    </dependencySet> 
    <dependencySet> 
     <scope>test</scope> 
     <includes> 
       <include>*:jar:*</include> 
      </includes> 
     <outputDirectory>/online-store/lib</outputDirectory> 
    </dependencySet> 
    </dependencySets> 
</assembly> 
+0

完美。這是解決方案 –