如何在干净安装时将多个jar文件发布到maven

时间:2010-05-07 15:24:16

标签: maven-2 maven-assembly-plugin

我有一个使用maven程序集插件从一个jar创建多个jar现在的问题是我必须将这些jar发布到本地repo,就像其他maven jar发布时他们自己构建maven clean install我怎么能这样做

这是我的pom文件

<project>
 <parent>
  <groupId>parent.common.bundles</groupId>
  <version>1.0</version>
  <artifactId>child-bundle</artifactId>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 <groupId>common.dataobject</groupId>
 <artifactId>common-dataobject</artifactId>
 <packaging>jar</packaging>
 <name>common-dataobject</name>
 <version>1.0</version>
 <dependencies>
      </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.jibx</groupId>
    <artifactId>maven-jibx-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
     <directory>src/main/resources/jibx_mapping</directory>
     <includes>
      <includes>binding.xml</includes>
     </includes>
     <verbose>false</verbose>
    </configuration>
    <executions>
     <execution>
      <goals>
       <goal>bind</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
   <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
     <execution>
      <id>make-business-assembly</id>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
      <configuration>
       <appendAssemblyId>false</appendAssemblyId>
       <finalName>flight-dto</finalName>
       <descriptors>
        <descriptor>src/main/assembly/car-assembly.xml</descriptor>
       </descriptors>
       <attach>true</attach>
      </configuration>
     </execution>
     <execution>
      <id>make-gui-assembly</id>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>
      <configuration>
       <appendAssemblyId>false</appendAssemblyId>
       <finalName>app_gui</finalName>
       <descriptors>
        <descriptor>src/main/assembly/bike-assembly.xml</descriptor>
       </descriptors>
       <attach>true</attach>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

  </project>

这是我的汇编文件

<assembly>
  <id>app_business</id>
  <formats>
    <format>jar</format>
  </formats>
  <baseDirectory>target</baseDirectory>
  <includeBaseDirectory>false</includeBaseDirectory>

  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
      <outputDirectory></outputDirectory> 
      <includes>
        <include>com/dataobjects/**</include>
      </includes>
    </fileSet>    
  </fileSets>
</assembly>

2 个答案:

答案 0 :(得分:17)

Build Helper Maven Plugin有一个build-helper:attach-artifact,可以附加要安装和部署的其他工件。它通常像这样使用(来自Usage页面):

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <!-- add configuration for antrun or another plugin here -->
      </plugin>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>some file</file>
                  <type>extension of your file </type>
                  <classifier>optional</classifier>
                </artifact>
                ...
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

答案 1 :(得分:2)

非常感谢Pascal,这件事确实有效。 这是我添加的配置也让它工作..

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>abc</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>src/main/assembly/flight-assembly.xml</file>
                  <type>xml</type>
                  <classifier>flight</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
  </plugin>