发布项目到中央库

其实网上关于前面的配置pom之类的说的都基本没问题。就是最后关于自动发布release版本和Nexus Repository Manager的关系没怎么说清楚。

参考资料

Sonatype中央库

  • http://central.sonatype.org/

项目发布教程

  • http://central.sonatype.org/pages/ossrh-guide.html#deployment

开源协议介绍

  • http://www.gnu.org/licenses/license-list.html
  • http://www.open-open.com/solution/view/1319816219625

提交issue

  • 创建Sonatype的Jira账号:https://issues.sonatype.org/secure/Signup!default.jspa

  • 提交issue:https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

    审核需要两三天,主要注意groupid的命名,如果用域名后缀需要确保自己拥有域名。

安装gpg

  • 教程:http://central.sonatype.org/pages/working-with-pgp-signatures.html

    我下载的是gpg2,所有命令都是gpg2开头的。

    记住passPhrase

    gpg --gen-key
    gpg2 --list-keys  显示公钥
    gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys 你的公钥
    

使用maven管理签名和部署项目

  • 教程:http://central.sonatype.org/pages/apache-maven.html

  • 需要的组件:http://central.sonatype.org/pages/requirements.html

  • 在pom中添加必须的信息,如开原协议,开发人员信息,name,url,scm等。还要在pom里添加三个plugin,source、javadoc、gpg。

    pom示例:https://github.com/simpligility/ossrh-demo/blob/master/pom.xml

    • 使用profile的例子,强烈建议使用profile,不然平时编译都很慢。
    <distributionManagement>
    	<snapshotRepository>	
    		<id>ossrh</id>
    		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
    	</snapshotRepository>
    	<repository>
    		<id>ossrh</id>
    		<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    	</repository>
    </distributionManagement>
    
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.7</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <configuration>
                            <excludePackageNames>*thrift*</excludePackageNames>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

    这里nexus-staging-maven-plugin中的标签设置为true。则mvn deploy后会自动部署到Sonatype并且自动发布到中央库中了。

    需要把项目中的javadoc完善,不然deploy无法通过

  • 将M2_HOME/conf下的settings.xml拷贝到.m2下,然后添加nexus的server和gpg的profile

    <servers>
        <server>
          <id>ossrc</id>
          <username>repouser</username>
          <password>repopwd</password>
        </server>
    </servers>
    <profiles>
    	<profile>
          <id>ossrh</id>
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
          <properties>
            <gpg.executable>gpg2</gpg.executable>
            <gpg.passphrase>生成key-pair时设置的passphrase</gpg.passphrase>
          </properties>
    	</profile>
    <profiles>
    

这里的server去https://oss.sonatype.org登录并且点击用户名->profile->user token->access user token

部署snapshot版

  • 在pom中将版本号加上-SNAPSHOT,并且mvn clean deploy就可以部署snapshot版本了。
mvn clean deploy -P release

  • 部署之后在这个网址查看文件:https://oss.sonatype.org/content/repositories/snapshots/

自动部署release版

  • 教程:http://central.sonatype.org/pages/releasing-the-deployment.html

  • 如果nexus-staging-maven-plugin中的标签设置为true。则自动部署到Sonatype并且自动发布到中央库中了。

  • 将pom中的-SNAPSHOT去掉,并且 mvn clean deploy -P release,就可以直接部署到中央库了。

这种在Nexus staging repository(https://oss.sonatype.org/#welcome)是找不到的,都被自动close->release->drop了。而drop之后就没有了。

手动部署release版

  • 如果nexus-staging-maven-plugin中的标签设置为false。则需要手动发布到中央库中。
mvn clean deploy -P release
  • 这时项目会部署到Nexus Repository Manager,并自动close,但不会release,需要手动release。手动release时会提示自动drop。
  • 可在这查看:https://oss.sonatype.org/#welcome
  • 刷新,选中repository。如果有问题,可以点上方的drop删除缓存库。
  • 点击release按钮发布

通知管理员

最后记得在之前提的issue上提个comment,告诉管理员已经发布release版了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值