我们有一个网关客户端项目,它是多模块 Maven 项目的一部分。gateway-client pom.xml 配置为创建两个主要工件:gateway-client.jar 和 gateway-services-client.jar 并将它们部署到两个单独的 Nexus 存储库:分别是 Releases 存储库和 3rd 方存储库。这是通过默认激活的配置文件完成的:
<profile>
<!-- ====================================================================== -->
<!-- default Profile -->
<!-- This is the default profile which will run by default. This profile -->
<!-- produces two client artifacts: gateway-client and gateway-services-client -->
<!-- for the releases and thirdparty repositories respectively. -->
<!-- ====================================================================== -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- ====================================================================== -->
<!-- default Profile Build plugins -->
<!-- ====================================================================== -->
<build>
<plugins>
<!-- ====================================================================== -->
<!-- default Profile Maven deploy plugin -->
<!-- ====================================================================== -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-thirdparty-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>${nexus.url}/content/repositories/thirdparty</url>
<repositoryId>thirdparty</repositoryId>
<file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
<groupId>${project.groupId}</groupId>
<artifactId>gateway-services-client</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>deploy-release-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>${nexus.url}/content/repositories/releases</url>
<repositoryId>releases</repositoryId>
<file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
<groupId>${project.groupId}</groupId>
<artifactId>gateway-client</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
问题是因为这个配置文件在默认情况下是活动的,如果我们尝试运行 amvn deploy
并且 GAV 坐标的版本是 -SNAPSHOT,构建仍然会无意中尝试部署到 Nexus 3rd Party 并发布 repos 并且失败,因为它当然是不接受 -SNAPSHOT 工件版本。为了解决这个问题,我专门为 -SNAPSHOT 版本设置了一个配置文件,它只会部署到快照存储库:
<profile>
<!-- ====================================================================== -->
<!-- snapshot Profile -->
<!-- Activating this profile will automatically deactivate the default profile. -->
<!-- The purpose of this profile is to produce a a gateway-services-client and gateway-client -->
<!-- snapshot artifacts and deploy them to the snapshots Nexus repository where they can -->
<!-- act as the latest development dependencies for other projects -->
<!-- ====================================================================== -->
<id>snapshot</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<!-- ====================================================================== -->
<!-- snapshot profile Build plugins -->
<!-- ====================================================================== -->
<build>
<plugins>
<!-- ====================================================================== -->
<!-- snapshot profile Maven deploy plugin -->
<!-- ====================================================================== -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-thirdparty-snapshot-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>${nexus.url}/content/repositories/snapshots</url>
<repositoryId>snapshots</repositoryId>
<file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
<groupId>${project.groupId}</groupId>
<artifactId>gateway-services-client</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
这样做的问题是您必须在执行 Maven 命令时指定配置文件:mvn deploy -P 'snapshot'
. 我的问题是我该怎么做才能在mvn deploy
不指定快照配置文件的情况下运行,并让构建自动部署到快照存储库或第 3 方并发布存储库,所有这些都基于版本中 -SNAPSHOT 的存在GAV 坐标?