Maven创build临时邮编工件的最佳实践

假设我需要pipe理由作为zip存档卷起的多文件夹/文件结构组成的工件。 我不清楚如何以最适合“Maven方式”的方式在Maven中实现这一点。

我知道没有“拉链”包装types。 这是否意味着在Maven中没有通用的生命周期来简单地将资源文件夹中的内容压缩,然后将其安装/部署到我的存储库?

我在寻找select,评估每个选项如何满足我遵循maven方式的要求,因为我不希望产生明显的偏离黄金道路的惩罚。 。 。

决定你将使用什么分类器为你的zip文件,为了争论让我们说这将是sample

在你的项目中创build文件assembly/sample.xml

用这样的东西填充assembly/sample.xml

 <?xml version="1.0" encoding="UTF-8"?> <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>sample</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <outputDirectory>/</outputDirectory> <directory>some/directory/in/your/project</directory> </fileSet> </fileSets> <!-- use this section if you want to package dependencies --> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <excludes> <exclude>*:pom</exclude> </excludes> <useStrictFiltering>true</useStrictFiltering> <useProjectArtifact>false</useProjectArtifact> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly> 

把它添加到你的pom的build部分

  <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>create-distribution</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>assembly/sample.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins> </build> 

因此,它应该创build并安装you-project-name-VERSION-sample.zip

我build议你阅读Sonatype的maven书籍的章节: https : //books.sonatype.com/mvnref-book/reference/assemblies.html

另外,阅读汇编格式规范: http : //maven.apache.org/plugins/maven-assembly-plugin/assembly.html

用这样的东西填充程序集/ sample.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>install</id> <baseDirectory>/</baseDirectory> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <includes> <include>README*</include> <include>*.sh</include> </includes> </fileSet> <fileSet> <directory>target/classes/</directory> <outputDirectory>resources</outputDirectory> <includes> <include>*.properties</include> <include>*.xml</include> </includes> <lineEnding>dos</lineEnding> </fileSet> <!-- <fileSet> <directory>target/</directory> <outputDirectory>lib</outputDirectory> <includes> <include>*.jar</include> </includes> <lineEnding>dos</lineEnding> </fileSet> --> </fileSets> <!-- use this section if you want to package dependencies --> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <excludes> <exclude>*:pom</exclude> </excludes> <useStrictFiltering>true</useStrictFiltering> <useProjectArtifact>true</useProjectArtifact> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly> 

在pom.xml文件中添加下面的代码。

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptor>assembly/sample.xml</descriptor> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> 

运行命令为mvn package -P dev -Dmaven.test.skip

将创build包含以下内容的zip文件:xxxx.zip -lib / .jar -resources / .xml / properties -readme -start.sh