Maven Assembly分发jar-with-dependency包括只有google guava的jar

时间:2012-11-13 16:47:52

标签: maven maven-assembly-plugin

我有一个多模块项目,不同的模块使用google guava作为依赖项。另一个子模块仅用于为所有示例中的项目构建分发。在那个项目中,我使用程序集插件来创建带有依赖项的jar模块的目录。问题是,对于依赖于谷歌番石榴的每个项目,它创建一个独立的jar,没有'jar-with-dependencies'标签只包含google番石榴。

例如:

    parent
    |- moduleA
       |- pom.xml
       |-src
         |- ...   
    |- dist 
       |- pom.xml
       |- src
          |- main
             |- assembly
                |- assembly.xml
       | - target
          |- libs
             |- moduleA-XX.x-SNAPSHOT.jar
             |- moduleA-XX.x-SNAPSHOT-jar-with-dependencies.jar
   |- pom.xml

moduleA-XX.x-SNAPSHOT.jar仅包含google guava。我没想到会建一个只包含谷歌番石榴的罐子。

moduleA pom.xml

   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>

     <parent>
       <groupId>foor.bar</groupId>
       <artifactId>parent</artifactId>
       <version>0.0</version>
     </parent>

     <artifactId>commons</artifactId>
     <version>0.0-SNAPSHOT</version>
     <packaging>jar</packaging>

     <name>Commons</name>

     <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>

     <dependencies>
       <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>11.0</version>
       </dependency>
     </dependencies>

     <build>
       <!-- For annotations and other Java5 stuff -->
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>2.5.1</version>
           <configuration>
             <source>1.7</source>
             <target>1.7</target>
           </configuration>
         </plugin>
         <plugin>
           <artifactId>maven-assembly-plugin</artifactId>
           <version>2.3</version>
           <configuration>
             <descriptorRefs>
               <descriptorRef>jar-with-dependencies</descriptorRef>
             </descriptorRefs>
           </configuration>
           <executions>
             <execution>
               <id>make-assembly</id> 
               <phase>package</phase> <!-- bind to the packaging phase -->
               <goals>
                 <goal>single</goal>
               </goals>
             </execution>
           </executions>
         </plugin>
       </plugins>
     </build>
   </project>

dist assembly.xml

   <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
     <id>bin</id>
     <formats>
       <format>dir</format>
     </formats>
     <includeBaseDirectory>false</includeBaseDirectory>
     <moduleSets>
       <moduleSet>

         <!-- Enable access to all projects in the current multimodule build! -->
         <useAllReactorProjects>true</useAllReactorProjects>

         <!-- Now, select which projects to include in this module-set. -->
         <includes>
           <include>**</include>
         </includes>
         <binaries>
           <attachmentClassifier>jar-with-dependencies</attachmentClassifier>
           <outputDirectory>libs/</outputDirectory>
           <unpack>false</unpack>
         </binaries>
       </moduleSet>
     </moduleSets>
   </assembly>

0 个答案:

没有答案