Maven -压缩jar文件的简单插件



模块项目

 -1
  -pom.xml
 -2
  -pom.xml
 -3 
  -pom.xml
 -parent
  -pom.xml

和所有由父节点继承的模块。我所做的是编辑父pom,我想创建一个插件来构建zip与2 jar(从-1和-2)

我已经试过了

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution> <id>createDistJar</id> 
                    <goals> <goal>run</goal> </goals>  <phase>package</phase>
                    <configuration>
                        <target>
                            <echo message="${project.build.directory}"/>
                            <mkdir dir="${project.build.directory}"/>
                            <zip destfile="${project.build.directory}/JawaBot-${project.version}-dist.zip"
                                basedir="target/" includes="JawaBot-${project.version}-dist-rh/**">
                            </zip>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>uploadDistJar</id> <goals>  <goal>attach-artifact</goal>  </goals>
                    <phase>package</phase>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.directory}/JawaBot-${project.version}-dist.zip</file>
                                <type>zip</type>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>

但是它为所有/target文件夹中的所有模块创建zip。

创建一个单独的模块(xyz-dist),并附带一个附加的pom文件,该文件包含您希望成为发行版一部分的模块的依赖项。

在父节点中添加dist模块,如下:

  <modules>
      <module>dist</module>
      <module>package-1</module>
      <module>package-2</module>
  </modules>

dist模块中,将以下内容添加到pom中:

<project...>
  <parent>
  </parent>
  <packaging>pom</packaging>
  <dependencies>
      Dependencies of the modules you would like to package
  </dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-bundles</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/assembly/dist.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

dist.xml应包含以下内容:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>dist</id>
  <formats>
      <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
      <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <unpack>false</unpack>
          <scope>runtime</scope>
      </dependencySet>
  </dependencySets>
</assembly>

最新更新