{"id":95,"date":"2014-11-23T14:25:10","date_gmt":"2014-11-23T06:25:10","guid":{"rendered":"http:\/\/vinta.ws\/code\/?p=95"},"modified":"2026-03-17T01:20:11","modified_gmt":"2026-03-16T17:20:11","slug":"uploading-artifact-to-maven-central-repository","status":"publish","type":"post","link":"https:\/\/vinta.ws\/code\/uploading-artifact-to-maven-central-repository.html","title":{"rendered":"Upload your Java Artifacts to Maven Central Repository"},"content":{"rendered":"<p>\u4f60\u9700\u8981\uff1a<\/p>\n<ol>\n<li>\u4e00\u500b\u4f7f\u7528 Maven \u7ba1\u7406\u7684 Java project\uff08\u5ee2\u8a71\uff09<\/li>\n<li>\u4e00\u500b GPG key\uff08deploy \u7684\u6642\u5019\u6703\u7528\u4f86 sign \u8981\u63d0\u4ea4\u7684 .jar\uff09<\/li>\n<li>\u4e00\u500b Sonatype JIRA \u7684\u5e33\u865f<\/li>\n<li>\u958b\u4e00\u5f35 JIRA \u7684 ticket \u544a\u8a34 Sonatype \u7684\u4eba\u4f60\u8981\u767c\u4f48 library\uff0c\u544a\u77e5\u4ed6\u5011\u4f60\u7684 groupId<\/li>\n<li>\u6309\u7167 Requirements \u7684\u6307\u793a\u5b8c\u5584\u4f60\u7684 pom.xml<\/li>\n<li>deploy \u5230 snapshot repository<\/li>\n<li>deploy \u5230 staging repository<\/li>\n<li>\u5728 OSSRH \u7684 Staging Repositories \u628a\u4f60\u525b\u525b deploy \u7684 library \u7d66 close \u6389\uff0c\u9019\u6a23\u624d\u7b97\u662f release<\/li>\n<li>\u56de\u5230\u90a3\u5f35 ticket\uff0c\u901a\u77e5 Sonatype \u8b93\u4ed6\u5011\u628a\u4f60\u7684 library \u540c\u6b65\u5230 Maven Central Repositir<\/li>\n<\/ol>\n<p>\u6700\u5f8c\u4e00\u500b\u6b65\u9a5f\u53ea\u6709\u7b2c\u4e00\u6b21 release \u7684\u6642\u5019\u624d\u9700\u8981<br \/>\n\u4e4b\u5f8c release \u5c31\u6703\u81ea\u52d5\u540c\u6b65\u4e86<\/p>\n<h2>Requirements<\/h2>\n<p><a target=\"_blank\" href=\"http:\/\/maven.apache.org\/guides\/mini\/guide-central-repository-upload.html\">http:\/\/maven.apache.org\/guides\/mini\/guide-central-repository-upload.html<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/central.sonatype.org\/pages\/requirements.html\">http:\/\/central.sonatype.org\/pages\/requirements.html<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/central.sonatype.org\/pages\/ossrh-guide.html\">http:\/\/central.sonatype.org\/pages\/ossrh-guide.html<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/central.sonatype.org\/pages\/apache-maven.html\">http:\/\/central.sonatype.org\/pages\/apache-maven.html<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/central.sonatype.org\/pages\/releasing-the-deployment.html\">http:\/\/central.sonatype.org\/pages\/releasing-the-deployment.html<\/a><\/p>\n<p>\u53c3\u8003 Pangu.java \u7684 pom.xml<br \/>\n<a target=\"_blank\" href=\"https:\/\/github.com\/vinta\/pangu.java\/blob\/master\/pom.xml\">https:\/\/github.com\/vinta\/pangu.java\/blob\/master\/pom.xml<\/a><\/p>\n<h2>Deployment<\/h2>\n<p>You need the following plugins:<\/p>\n<ul>\n<li>maven-source-plugin<\/li>\n<li>maven-javadoc-plugin<\/li>\n<li>maven-gpg-plugin<\/li>\n<li>nexus-staging-maven-plugin<\/li>\n<li>maven-release-plugin<\/li>\n<\/ul>\n<p>deploy \u4e4b\u524d<br \/>\n\u5fc5\u9808\u78ba\u5b9a\u4f60\u7684 local \u7684\u7a0b\u5f0f\u78bc\u8ddf scm \u7684\u7a0b\u5f0f\u78bc\u662f\u540c\u6b65\u7684<br \/>\n\u5982\u679c\u4f60\u8981\u767c\u5e03 <code>1.0.0<\/code> \u7248\u672c\u7684\u8a71<br \/>\n\u4f60\u7684 pom.xml \u88e1\u8981\u5beb <code>1.0.0-SNAPSHOT<\/code><br \/>\n\u7136\u5f8c\u57f7\u884c\uff1a<\/p>\n<pre class=\"line-numbers\" data-label=\"bash\"><code class=\"language-bash\"># deploy to snapshot repository\n$ mvn clean deploy<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u5728 <a target=\"_blank\" href=\"https:\/\/oss.sonatype.org\/\">https:\/\/oss.sonatype.org\/<\/a> \u641c\u5c0b\u5230<br \/>\nSNAPSHOT \u7248\u672c\u6e2c\u8a66\u90fd\u6c92\u554f\u984c\u4e4b\u5f8c\uff08\u7576\u7136\u4f60\u8981\u5148\u8a2d\u5b9a\u8b93 Maven \u80fd\u5920\u4e0b\u8f09 SNAPSHOT \u7248\u672c\u7684 libraries\uff09<br \/>\n\u5c31\u53ef\u4ee5\u6b63\u5f0f release \u4e86\uff1a<\/p>\n<pre class=\"line-numbers\" data-label=\"bash\"><code class=\"language-bash\"># cleanup for the release\n$ mvn release:clean\n\n# \u8981\u56de\u7b54\u4e00\u4e9b\u95dc\u65bc\u7248\u672c\u865f\u7684\u554f\u984c\n# \u5b83\u6703\u81ea\u52d5\u5e6b\u4f60\u65b0\u589e\u4e00\u500b tag \u4e26\u4e14\u628a pom.xml \u88e1\u7684 <code>&lt;version&gt;<\/code> \u6539\u6210\u4e0b\u500b\u7248\u672c\n$ mvn release:prepare\n\n# deploy to staging repository\n# \u7136\u5f8c Maven \u6703\u628a\u4e0a\u4e00\u6b65\u65b0\u589e\u7684 git tag \u548c pom.xml \u7684\u8b8a\u66f4\u76f4\u63a5 push \u5230 GitHub\n$ mvn release:perform<\/code><\/pre>\n<p>Maven \u6703\u81ea\u52d5\u5728 library \u9032\u5230 staging repository \u7684\u6642\u5019\u628a <code>-SNAPSHOT<\/code> \u5b57\u4e32\u62ff\u6389<\/p>\n<p>\uff08\u7b2c\u4e00\u6b21 release \u624d\u9700\u8981\u4ee5\u4e0b\u7684\u52d5\u4f5c\uff09<\/p>\n<p>\u7136\u5f8c\u4f60\u5c31\u53ef\u4ee5\u5728 <a target=\"_blank\" href=\"https:\/\/oss.sonatype.org\/#stagingRepositories\">https:\/\/oss.sonatype.org\/#stagingRepositories<\/a><br \/>\n\u627e\u5230\u4f60\u525b\u525b deploy \u7684 library<br \/>\n\u901a\u5e38\u9577\u5f97\u50cf\u662f <code>wsvinta-1000<\/code>\uff08\u524d\u9762\u662f groupId\uff09<br \/>\n\u8981\u628a\u5b83 close<br \/>\n\u7136\u5f8c\u518d release<\/p>\n<p>\u9664\u4e86\u7b2c\u4e00\u6b21 release \u8981\u53bb ticket \u7559\u8a00\u4e4b\u5916<br \/>\n\u4e4b\u5f8c release \u5c31\u6703\u81ea\u52d5\u540c\u6b65\u5230 Maven Central Repository<br \/>\n\u4e0d\u904e\u901a\u5e38\u6703\u9700\u8981\u7b49\u4e00\u9663\u5b50\u624d\u6703\u5728 Maven \u4e0a\u770b\u5230<\/p>\n<p>ref:<br \/>\n<a target=\"_blank\" href=\"http:\/\/dev.solita.fi\/2014\/10\/22\/publishing-to-maven-central-repository.html\">http:\/\/dev.solita.fi\/2014\/10\/22\/publishing-to-maven-central-repository.html<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/lkrnac.net\/blog\/2014\/03\/deploy-to-maven-central\/\">http:\/\/lkrnac.net\/blog\/2014\/03\/deploy-to-maven-central\/<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/kirang89.github.io\/blog\/2013\/01\/20\/uploading-your-jar-to-maven-central\/\">http:\/\/kirang89.github.io\/blog\/2013\/01\/20\/uploading-your-jar-to-maven-central\/<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/superwang.me\/2014\/03\/22\/publish-your-library-to-maven-central-repository-part-1\/\">http:\/\/superwang.me\/2014\/03\/22\/publish-your-library-to-maven-central-repository-part-1\/<\/a><br \/>\n<a target=\"_blank\" href=\"http:\/\/www.kongch.com\/2013\/05\/deploy-to-central-repo\/\">http:\/\/www.kongch.com\/2013\/05\/deploy-to-central-repo\/<\/a><\/p>\n<p>\u5982\u679c\u4f60\u5728 release \u7684\u904e\u7a0b\u4e2d\u51fa\u4e86\u932f<br \/>\n\u8981\u91cd\u65b0 release \u7684\u8a71<br \/>\n\u4f60\u5f97 revert \u4f60\u7684 git commit \u5230\u57f7\u884c <code>mvn release:prepare<\/code> \u4e4b\u524d<br \/>\n\u7136\u5f8c\u518d\u91cd\u65b0\u8dd1\u4e00\u6b21<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Publishing a Java library to Maven Central: a GPG key, a Sonatype JIRA account, a ticket for your groupId, then deploy to snapshot and staging. Only the first release needs the ticket.<\/p>\n","protected":false},"author":1,"featured_media":771,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[41,42],"class_list":["post-95","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-about-misc","tag-java","tag-maven"],"_links":{"self":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":0,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media\/771"}],"wp:attachment":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}