简体   繁体   中英

Simultaneously deploy artifact to Maven Central and internal Nexus

I have a project which deploys to Maven Central via OSSRH using the Maven release and nexus-staging-maven plugins using the directions from http://central.sonatype.org/pages/ossrh-guide.html and http://central.sonatype.org/pages/apache-maven.html .

This works fine, but it often takes several hours for the artifact to be visible on Maven Central. Often we would like to make use of the deployed artifact immediately, so we end up deploying it from our local repositories to our internal Nexus server using deploy:deploy-file . This works but it is inelegant and easy to forget to do. Is there any way to make Maven deploy to an internal Nexus as well as Maven Central as part of the release process?

Note: This question is similar to, but not quite the same as, https://stackoverflow.com/questions/29019682/promote-artifact-from-internal-nexus-repository-to-maven-central

Add an additional execution to the maven-deploy-plugin :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-deploy-plugin</artifactId>
  <version>${maven.deploy.plugin.version}</version>
  <executions>
    <execution>
      <id>nexus-deploy</id>
      <phase>deploy</phase>
      <goals>
        <goal>deploy</goal>
      </goals>
      <configuration>
        <altDeploymentRepository>yourNexusRepo</altDeploymentRepository>
      </configuration>
    </execution>
  </executions>
</plugin>

The yourNexusRepo value will look something like this:

releases::default::https://nexus.host.org/nexus/content/repositories/releases

You should be able to get the exact URL from Nexus. The part before the first :: is the repository ID.

We solved this problem by no longer using nexus-staging-maven-plugin as an extension. This is described at https://help.sonatype.com/repomanager2/staging-releases/configuring-your-project-for-deployment :

If more control is desired over when the plugins deploy goal is activated or if Maven 2 is used, you have to explicitly deactivate the Maven Deploy plugin and replace the Maven Deploy plugin invocation with the Nexus Staging Maven plugin...

In our case, we disabled the default-deploy execution by setting <phase>none</phase> . Our full solution is available at https://github.com/newmediaworks/nmw-oss-parent/commit/a7377a158feded473cb2f1618449e34173c22252 which includes an additional execution of maven-deploy-plugin in the jenkins-deploy profile.

The key takeaway follows, which so far seems to behave as if extension were enabled, but does not interfere with additional maven-deploy-plugin executions:

<plugins>
    <plugin>
        <groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId>
        <!--
        Not using as extension, since it blocks maven-deploy-plugin in the jenkins-deploy profile:
        <extensions>true</extensions>
        -->
        <executions>
            <execution>
                <!-- Manually added since nexus-staging-maven-plugin is not used as extension -->
                <id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId>
        <executions>
            <execution>
                <!-- Manually disabled since nexus-staging-maven-plugin is not used as extension -->
                <id>default-deploy</id><phase>none</phase>
            </execution>
        </executions>
    </plugin>
</plugins>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM