【发布时间】:2020-08-07 12:04:03
【问题描述】:
我正在尝试使用 maven v3 为非 Java 项目创建 tar.gz 输出,以便部署到 nexus。我无法在 pom 文件的打包选项中指定 tar。除非弄错了,否则我可以在运行 mvn deploy 时将 tar 指定为打包选项。无论如何我可以在 pom 文件本身中指定它吗?
【问题讨论】:
标签: maven maven-3 maven-deploy-plugin
我正在尝试使用 maven v3 为非 Java 项目创建 tar.gz 输出,以便部署到 nexus。我无法在 pom 文件的打包选项中指定 tar。除非弄错了,否则我可以在运行 mvn deploy 时将 tar 指定为打包选项。无论如何我可以在 pom 文件本身中指定它吗?
【问题讨论】:
标签: maven maven-3 maven-deploy-plugin
您可以创建 TAR.GZ 文件并将其“附加”到主要工件。我有一个示例将 WAR 重新打包到GitHub 上的 Linux 服务中。关键步骤是打包程序集:
<project ...>
...
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
<formats>
<format>tar.gz</format>
</formats>
<descriptorSourceDirectory>src/main/assemblies</descriptorSourceDirectory>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
...
</plugins>
</build>
</project>
<attach>true</attach> 安装工件。本例中的程序集为:
<?xml version="1.0" encoding="UTF-8"?>
<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>bin</id>
<baseDirectory>${artifactId}-${version}</baseDirectory>
<files>
<file>
<outputDirectory>bin</outputDirectory>
<source>
${project.build.directory}/${project.build.finalName}.jar
</source>
<filtered>false</filtered>
<destName>${artifactId}.jar</destName>
</file>
</files>
<fileSets>
<fileSet>
<outputDirectory>bin</outputDirectory>
<directory>${project.basedir}/src/bin</directory>
<includes>
<include>${artifactId}.conf</include>
</includes>
<filtered>true</filtered>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>*:*-x86_64:*</include>
</includes>
<scope>runtime</scope>
<outputFileNameMapping>
lib${artifact.artifactId}.${artifact.type}
</outputFileNameMapping>
</dependencySet>
</dependencySets>
</assembly>
但您需要找到/创建一个适合您的用例。
【讨论】: