发布构建到maven中央仓库的方法和详细步骤
Maven项目托管在Apache上的,但是中央仓库不是Apache的资源,中央仓库是由Sonatype出资维护的。目前来说,http://repo1.maven.org/maven2/是真正的Maven中央仓库的地址。Nexus仓库就是Sonatype开发的,搭建maven私服普遍采用Nexus。
<name>Gecco</name> <description>Easy to use lightweight web crawler</description> <url>https://github.com/xtuhcy/gecco</url> <scm> <connection>scm:git:https://github.com/xtuhcy/gecco.git</connection> <developerConnection>scm:git:https://github.com/xtuhcy/gecco.git</developerConnection> <url>https://github.com/xtuhcy/gecco</url> <tag>v1.0.0</tag> </scm> <developers> <developer> <name>xtuhcy</name> <email>xtuhcy@163.com</email> <organization>geccocrawler</organization> <organizationUrl>http://www.geccocrawler.com</organizationUrl> </developer> </developers> <licenses> <license> <name>The MIT License (MIT)</name> <url>https://raw.githubusercontent.com/xtuhcy/gecco/master/LICENSE</url> </license> </licenses>?
<profiles> <profile> <id>release</id> <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> <build> <plugins> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <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-release-plugin</artifactId> <configuration> <autoVersionSubmodules>true</autoVersionSubmodules> <useReleaseProfile>false</useReleaseProfile> <releaseProfiles>release</releaseProfiles> <goals>deploy</goals> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> <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> <configuration> <encoding>UTF-8</encoding> </configuration> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>?
<servers> <server> <id>ossrh</id> <username>memory</username> <password>your password</password> </server> </servers>?
一切准备就绪,发布版本,mvn deploy -P release。编译后在签名是需要提供刚才生成gpg密钥时输入的密码??到此,一个构件已经发布到中央库,但是能正式下载还需要sonatype的工作人员审核。
回到sonatype网站的issue,回复issue,等待审核。审核通过的结果如下:??等待2个小时,您就可以在中央库下载自己的jar了。
这里说明一下自己使用的软件环境:maven3.2.2,eclipse luna
原文:http://xtuhcy.iteye.com/blog/2265895