マルチモジュールmavenプロジェクトの一部であるゲートウェイクライアントプロジェクトがあります。gateway-client pom.xml は、2 つの主要なアーティファクト (gateway-client.jar と gateway-services-client.jar) を作成し、それらを 2 つの別個の Nexus リポジトリ (それぞれリリース リポジトリとサード パーティ リポジトリ) にデプロイするように構成されています。これは、デフォルトでアクティブになっているプロファイルを介して行われます。
<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>
問題は、このプロファイルがデフォルトでアクティブであるためmvn deploy
、GAV 座標のバージョンが -SNAPSHOT である場合に実行しようとすると、ビルドが意図せずに Nexus サードパーティおよびリリース リポジトリにデプロイしようとして失敗することです。 -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
、スナップショット プロファイルを指定せずに実行し、バージョンの -SNAPSHOT の存在に基づいてビルドをスナップショット リポジトリまたはサード パーティおよびリリース リポジトリに自動的にデプロイするだけでよいようにするにはどうすればよいかということです。 GAV座標の?