gpt4 book ai didi

maven - 我如何将多个 Maven Artifact 部署到多个 Nexus 存储库,包括快照存储库而无需指定配置文件?

转载 作者:行者123 更新时间:2023-12-02 01:37:56 25 4
gpt4 key购买 nike

我们有一个网关客户端项目,它是多模块 Maven 项目的一部分。 gateway-client pom.xml 配置为创建两个主要 Artifact :gateway-client.jar 和 gateway-services-client.jar 并将它们部署到两个独立的 Nexus 存储库:分别是 Releases 存储库和 3rd Party 存储库。这是通过默认情况下处于事件状态的配置文件完成的:

<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 3rd Party 和 Releases repos 并失败,因为它当然不会接受 -SNAPSHOT Artifact 版本。为了解决这个问题,我专门为 -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 方和发布存储库所有基于在 GAV 坐标版本中是否存在 -SNAPSHOT?

最佳答案

我想到的唯一解决方案是使用属性并在部署期间添加三个执行。丑陋的是,在 SNAPSHOT 的情况下,您的 Artifact 将被部署两次到同一个存储库。

这是你可以做的:

<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>

然后添加三个执行,配置如下:

    <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>
...

关于maven - 我如何将多个 Maven Artifact 部署到多个 Nexus 存储库,包括快照存储库而无需指定配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29975515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com