【问题标题】:Publish snapshot and release both to Nexus using maven使用 maven 发布快照并发布到 Nexus
【发布时间】:2020-10-19 14:37:59
【问题描述】:

我关注了博客Maven Nexus DeployMaven Nexus Release,以便在 Nexus 中发布我构建的模块化 Spring Boot 应用程序。我正在使用 Nexus 开源和 Maven 3.6.0

我的计划是有一个设置,我可以根据我正在运行的 maven 目标发布快照和版本。我当前的 pom 包含以下详细信息 -

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>${maven-deploy-plugin.version}</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <configuration>
                    <skipSource>true</skipSource>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <releaseProfiles>releases</releaseProfiles>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<distributionManagement>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <url>http://localhost:8081/repository/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>nexus-releases</id>
        <url>http://localhost:8081/repository/releases</url>
    </repository>
</distributionManagement>
<scm>
    // my scm details
</scm>
<profiles>
    <profile>
        <id>releases</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.8</version>
                    <executions>
                        <execution>
                            <id>default-deploy</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <serverId>nexus-releases</serverId>
                        <nexusUrl>http://localhost:8081/nexus/</nexusUrl>
                        <skipStaging>true</skipStaging>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

我的 maven settings.xml 包含服务器条目 -

<server>
    <id>nexus-releases</id>
    <username>deployment</username>
    <password>deployment</password>
</server>
<server>
    <id>nexus-snapshots</id>
    <username>deployment</username>
    <password>deployment</password>
</server>

当我运行命令时

mvn -B release:clean release:prepare release:perform -Darguments="-DskipTests -Dmaven.javadoc.skip=true"

它工作正常,我的发布版本已上传到 Nexus 发布路径。

我的问题是 -

  1. 我应该运行哪个命令来创建我的快照版本并将其上传到 Nexus 快照路径?

  2. 如果命令是mvn clean deploy,我试过了,它仍然没有将快照上传到 Nexus。上述命令中部署步骤的输出是 -

    [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ company-service --- [INFO] 跳过工件部署

编辑 1 -

我跑了mvn clean deploy -X,部署插件的日志是-

[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ company-service ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-deploy-plugin:2.8.2, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy' with basic configurator -->
[DEBUG]   (f) artifact = com.exa:company-service:jar:0.0.13-SNAPSHOT
[DEBUG]   (f) attachedArtifacts = []
[DEBUG]   (f) deployAtEnd = false
[DEBUG]   (s) localRepository =       id: local
      url: file:///root/.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => always]

[DEBUG]   (f) offline = false
[DEBUG]   (f) packaging = jar
[DEBUG]   (f) pomFile = /home/dell/repos/exa/exa-microservices/company-service/pom.xml
[DEBUG]   (f) project = MavenProject: com.exa:company-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/company-service/pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: com.exa:exa-microservices:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/pom.xml, MavenProject: com.exa:discovery-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/discovery-service/pom.xml, MavenProject: com.exa:gateway-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/gateway-service/pom.xml, MavenProject: com.exa:common-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/common-service/pom.xml, MavenProject: com.exa:auth-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/auth-service/pom.xml, MavenProject: com.exa:device-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/device-service/pom.xml, MavenProject: com.exa:installer-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/installer-service/pom.xml, MavenProject: com.exa:company-service:0.0.13-SNAPSHOT @ /home/dell/repos/exa/exa-microservices/company-service/pom.xml]
[DEBUG]   (f) retryFailedDeploymentCount = 1
[DEBUG]   (f) skip = true
[DEBUG]   (f) updateReleaseInfo = false
[DEBUG] -- end configuration --
[INFO] Skipping artifact deployment
[INFO] ------------------------------------------------------------------------

【问题讨论】:

    标签: java maven nexus


    【解决方案1】:

    如果您将要部署的资产的version 更改为包含-SNAPSHOT,它将自动使用快照存储库。

    例如,6.2.0 将在您执行 mvn deploy 或您的发布命令时转到发布仓库。

    当您执行mvn deploy 或您的发布命令时,6.2.0-SNAPSHOT 将转到快照存储库。

    也删除这个:

    <configuration>
        <skip>true</skip>
    </configuration>
    

    从您的 maven-deploy-plugin 开始,您将开始运行!

    【讨论】:

    • 我在 pom 中的版本标签包含快照&lt;version&gt;0.0.13-SNAPSHOT&lt;/version&gt;。当我运行发布目标时,版本更改为 0.0.14-SNAPSHOT,发布版本使用 0.0.13 创建并发布到 Nexus 中的发布路径。但是快照版本没有发布到 Nexus。当我使用快照版本运行 mvn clean deploy 时,没有任何反应。
    • 您能发布 mvn clean deploy 的完整日志吗?如果这并没有显示太多,请在 mvn clean deploy -X 上运行它并发布该日志的相关部分
    • @abi_pat 添加了我认为可以解决的问题。您在 pom 的部署配置中有 &lt;skip&gt;true&lt;/skip&gt;
    • 那我就糊涂了。如果我删除跳过配置,哪个插件将为部署目标执行 - Maven deploy 或 Nexus staging maven?因为我尝试删除然后运行 ​​release 命令,它给了我错误。
    • 错误 - [错误] 无法执行目标 org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (default-deploy) on project company-service: 未能部署工件:无法将工件 com.pct:auth-service:jar:0.0.13 从/到 nexus-releases (localhost:8081/repository/releases) 传输:无法传输文件:localhost:8081/repository/releases/com/pct/auth-service/0.0.13/…。返回码为:400,ReasonPhrase:Repository 不允许更新 assets:releases。
    猜你喜欢
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2017-09-18
    相关资源
    最近更新 更多