automate deployment to sonatype's oss maven repository

孤者浪人 提交于 2019-12-03 06:59:10

For the convenience of Maven projects, Sonatype is providing a parent POM you can add to your project with all the basic configuration:

https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-Changesto%7B%7Bpom.xml%7D%7D

The important bits are:

  <parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>7</version>
  </parent>

And the source code repository details:

  <scm>
    <connection>scm:svn:http://foo.googlecode.com/svn/trunk/</connection>
    <developerConnection>scm:svn:https://foo.googlecode.com/svn/trunk/</developerConnection>
    <url>http://foo.googlecode.com/svn/trunk/</url>
  </scm>

You will also need GPG to be install on your computer (Required to sign the packages) and our settings.xml correctly filled with your credentials:

  <servers>
    <server>
      <id>sonatype-nexus-snapshots</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
  </servers>

After that, you should be able to use the two steps release:

$ mvn release:prepare

$ mvn release:perform

Unfortunately, I don't know any way of automate the manual approval part of the process (In oss.sonatype.org). But that should already save you some times.

The documentation, as shown above, is probably a bit convoluted but is very complete and gives you all you need to know for various scenarios.

EDIT:

In fact I think I am wrong and there is a part on automate approval process. Interesting.

And for this part you are right, the details are quite limited. Though, I hope the first part of the configuration already helps you a little bit. I need to look further into this staging stuff (Or maybe someone else would have already done it !)

EDIT_AGAIN:

I need to actually try it but it would sound like something as follow:

        <plugins>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- The Base URL of Nexus instance where we want to stage -->
                    <nexusUrl>https://oss.sonatype.org/service/local/staging/deploy/maven2/</nexusUrl>
                    <serverId>sonatype-nexus-staging</serverId>
                </configuration>
            </plugin>
        </plugins>

According to the documentation, the deploy should be replaced by the right staging workflow (Including the close) and it would left the latest step:

$ mvn nexus-staging:release -Ddescription="Yippie!"

TO BE TESTED...

So 95% automated but I still need to figure out the stagingRepositoryId every time.

You can use mvn nexus-staging:rc-list

Specifically, by doing mvn release:rc-list and using grep or whatever to filter the output from that by some form of the group ID or other substring that you know the stagingRepositoryId to be, you can determine the full stagingRepositoryId value

For example, the group ID for my project is nu.validator and my stagingRepositoryId values are all in the form nuvalidator-NNNN where the NNNN part is a number that started from 1000 with my first release and that the system increments by 1 each time I release; so nuvalidator-1000, nuvalidator-1001, and so on.

So in the python script I use for my build, I just do this:

output = subprocess.check_output("mvn nexus-staging:rc-list  -DnexusUrl=https://oss.sonatype.org/ -DserverId=ossrh")
for line in output.split('\n'):
    if "nuvalidator" in line:
        stagingRepositoryId = "nuvalidator-" + line[8:23]
        ...

That's because the relevant lines returned in the mvn nexus-staging:rc-list output are in the form:

...
[INFO] central_bundles-3514 OPEN     Implicitly created (auto staging).
[INFO] central_bundles-3515 OPEN     Implicitly created (auto staging).
[INFO] central_bundles-3521 OPEN     Implicitly created (auto staging).
[INFO] nuvalidator-1008     OPEN     Implicitly created (auto staging).
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!