自动部署到sonatype的oss maven存储库

我有几个github java项目。 其中一个我手动部署到sonatype的存储库,以便它在maven中心发布。

这是一个有点痛苦的过程,因为它似乎涉及太多的箍以跳过和大量的手动工作,我想自动化。 所以我实际上已经停止这样做了,因为这只是太多的工作。 有大量的文档表明这是可能的,并且相当多的文档表明它以某种方式涉及使用nexus-staging-maven-plugin做一些事情。 不幸的是,所有这些文档都是(以典型的maven风格)跳过基本细节,这使我能够以简单的方式找出允许我自动将发布版本自动发布到sonatype存储库所需的最少步骤(即没有我手动批准的东西)。

那么,什么是我的pom中需要出现的模糊(假设一个标准的不复杂的java项目),包括sonatype存储库的url,我发现的所有文档似乎都坚持localhost:8081就是它,并且是必需的maven咒语让它做一个释放(最好通过mvn发布插件 ),让它签署工件,并让它将生成的工件部署到sonatype,批准,并准备好同步到maven central等。

所以,我正在寻找在ruby世界中替换“gem推”的maven,它可以在一个方便的单线上完成工作。 这是一个简单的例子,给出了一个由我批准的jar文件,我如何让它以最少量的大惊小怪结束在maven中心。

我非常感谢已经设置的pom文件的一些例子,我可以复制和改编。

编辑:

这是我工作的pom文件:

 4.0.0 com.jillesvangurp jsonj 1.34-SNAPSHOT JsonJ A framework for working with json in Java the "proper" way. No mappings or model classes, it's all just lovely json, but in Java. https://github.com/jillesvangurp/jsonj   MIT license https://github.com/jillesvangurp/jsonj/blob/master/LICENSE repo    git://git@github.com:jillesvangurp/jsonj.git scm:git:git@github.com:jillesvangurp/jsonj.git scm:git:git@github.com:jillesvangurp/jsonj.git    sonatype-nexus-snapshots Sonatype Nexus Snapshots https://oss.sonatype.org/content/repositories/snapshots  false   true      sonatype-nexus-snapshots Sonatype Nexus Snapshots https://oss.sonatype.org/content/repositories/snapshots/   sonatype-nexus-staging Nexus Release Repository https://oss.sonatype.org/service/local/staging/deploy/maven2/     jillesvangurp Jilles van Gurp http://www.jillesvangurp.com gmt+1  Main Developer     www.jillesvangurp.com http://jillesvangurp.com   UTF-8 UTF-8     org.apache.maven.plugins maven-compiler-plugin 2.5.1  true true 1.7 1.7    org.apache.maven.plugins maven-javadoc-plugin 2.8.1   documentation prepare-package  jar      org.apache.maven.plugins maven-source-plugin 2.2   gathersource prepare-package  jar      org.sonatype.plugins nexus-staging-maven-plugin 1.6 true   https://oss.sonatype.org/ sonatype-nexus-staging      wagon-webdav-jackrabbit org.apache.maven.wagon 2.2      org.apache.maven.plugins maven-release-plugin 2.1  forked-path false -Psonatype-oss-release        sonatype-oss-release    org.apache.maven.plugins maven-source-plugin   org.apache.maven.plugins maven-javadoc-plugin   org.apache.maven.plugins maven-gpg-plugin   sign-artifacts verify  sign           org.testng testng 6.8.7 test   junit junit     org.hamcrest hamcrest-all 1.3 test   com.googlecode.json-simple json-simple 1.1.1   junit junit     xom xom 1.2.5 true   commons-lang commons-lang 2.6   com.jillesvangurp efficientstring 1.11   com.fasterxml.jackson.core jackson-core 2.2.3    

下面的评论(@ aurelien-thieriot)让我走上了正确的轨道但本身还不够。

最后我拿了sonatype父pom并将它压平成我的pom文件。

这允许我正常使用mvn发布插件 。 它将工件上载到sonatype staging存储库。 然后为了发布工件,我实际上需要staging存储库id。 您可以从https://oss.sonatype.org/index.html#stagingRepositories中的存储库视图中找到它。

在我的情况下,命令行变为:

 mvn nexus-staging:release -Ddescription="Release 1.33" -DstagingRepositoryId=comjillesvangurp-1002 

如果没有正确的ID,它就无法解决并仍然失败: Sonatype Maven Staging Plugin Issue

所以95%自动化,但我仍然需要每次都找出stagingRepositoryId

编辑:

mvn release:perform实际上告诉你staging存储库的id。 我猜你可以编写一个脚本,从输出中提取这个id,然后将其传递给下一步。 如果有人知道一些mvn voodoo来制作mvn release:perform执行暂存版本,我将不胜感激。

为了方便Maven项目,Sonatype提供了一个父POM,您可以使用所有基本配置添加到项目中:

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

重要的是:

   org.sonatype.oss oss-parent 7  

和源代码存储库详细信息:

   scm:svn:http://foo.googlecode.com/svn/trunk/ scm:svn:https://foo.googlecode.com/svn/trunk/ http://foo.googlecode.com/svn/trunk/  

您还需要在计算机上安装GPG(需要对软件包进行签名),并且我们的settings.xml正确地填充了您的凭据:

    sonatype-nexus-snapshots your-jira-id your-jira-pwd   sonatype-nexus-staging your-jira-id your-jira-pwd   

之后,您应该可以使用两个步骤发布:

 $ mvn release:prepare $ mvn release:perform 

不幸的是,我不知道如何自动化流程的手动批准部分(在oss.sonatype.org中)。 但那应该可以节省你一些时间。

如上所示,文档可能有点复杂但非常完整,并为您提供了各种场景下您需要了解的所有信息。

编辑:

事实上,我认为我错了,自动审批流程也有一部分。 有趣。

对于这部分你是对的,细节是非常有限的。 虽然,我希望配置的第一部分已经帮助你一点点。 我需要进一步了解这个升级的东西(或者其他人可能已经完成了它!)

EDIT_AGAIN:

我需要实际尝试它,但它听起来像下面的东西:

    org.sonatype.plugins nexus-staging-maven-plugin 1.6 true   https://oss.sonatype.org/service/local/staging/deploy/maven2/ sonatype-nexus-staging    

根据文档,部署应该由正确的分段工作流程(包括关闭)替换,它将离开最新的步骤:

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

待测……

所以95%自动化,但我仍然需要每次都找出stagingRepositoryId。

您可以使用mvn nexus-staging:rc-list

具体来说,通过执行mvn release:rc-list并使用grep或其他任何方法来过滤某些forms的组ID或您知道stagingRepositoryId其他子字符串的stagingRepositoryId ,您可以确定完整的stagingRepositoryId

例如,我的项目的组ID是nu.validator ,我的stagingRepositoryId值都是nuvalidator-NNNNforms,其中NNNN部分是从我的第一个版本开始的1000的数字,系统每次增加1发布; 所以nuvalidator-1000nuvalidator-1001等等。

所以在我用于构建的python脚本中,我只是这样做:

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

那是因为在mvn nexus-staging:rc-list输出中返回的相关行的forms如下:

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