プロファイルを指定せずに、スナップショットリポジトリを含む複数のネクサスリポジトリに複数のMavenアーティファクトをデプロイするにはどうすればよいですか?

シェパルゾ

マルチモジュールMavenプロジェクトの一部であるゲートウェイクライアントプロジェクトがあります。Gateway-Client pom.xmlは、gateway-client.jarとgateway-services-client.jarの2つの主要なアーティファクトを作成し、それらをそれぞれリリースリポジトリとサードパーティリポジトリの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リポジトリにのみデプロイされる-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座標の?

クロード

私の頭に浮かぶ唯一の解決策は、プロパティを使用し、展開中に3つの実行を追加することです。醜いのは、SNAPSHOTの場合、アーティファクトが同じリポジトリに2回デプロイされることです。

これがあなたができることです:

<plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <id>eval-repo</id>
            <phase>initialize</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                    if (project.version.endsWith("-SNAPSHOT")){
                    project.properties.repoId = "snapshots";
                    project.properties.repoUrl = "snapshots url";
                    project.properties.thirdPartyRepoId =   "snapshots";
                    project.properties.thirdPartyRepoUrl = "snapshots url";                             
                    }
                    else {
                    project.properties.repoId = "releases";
                    project.properties.repoUrl = "releases url";
                    project.properties.thirdPartyRepoId =   "thirdparty";
                    project.properties.thirdPartyRepoUrl = "thirdparty url";                                    
                    }
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

次に、次の構成で3つの実行を追加します。

    <configuration>
        <artifactId>gateway-client</artifactId>
        <url>${repoUrl}</url>
        <repositoryId>${repoId}</repositoryId>
        ...

    <configuration>
        <artifactId>gateway-services-client</artifactId>
        <url>${repoUrl}</url>
        <repositoryId>${repoId}</repositoryId>
        ...

    <configuration>
        <artifactId>gateway-services-client</artifactId>
        <url>${thirdPartyRepoId}</url>
        <repositoryId>${thirdPartyRepoUrl}</repositoryId>
        ...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ