上传利用GitHub管理的软件到Maven Central Repository之一
笔者最近自己开发了一个开源项目PortletTester,代码托管在GitHub,使用Maven作为构建工具。为了使大家使用起来更加方便,决定尝试将项目发布到Maven的Central Repository上面,这样其他同样使用Maven的人要用的话只需要将PortletTester加入到pom.xml的dependency里就可以了,不用再GitHub网站上下载jar包,还要下载项目依赖的包。
这个过程可以说相当曲折,经过几个晚上的研究,终于把成功地发布了项目的第一个版本。现在把步骤和遇到的问题记录下来,方便有需要的人或者自己以后查阅。本文使用Sonatype Nexus作为代理仓库。也就是说先要把软件发布到这里,然后他们会帮同步到Maven的Central Repository上,这貌似是目前最简单有效的办法。
首先,修改pom.xml文件,使其满足下面这些要求:
下列标签填写正确 <modelVersion>
<groupId>
<artifactId>
<version>
<packaging>
<name>
<description>
<url>
<licenses>
<scm><url>
<scm><connection>
<developers>文件中不能包含<repositories>和<pluginRepositories>标签假如项目代码托管在GitHub等开源项目网站,<groupId>必须是com.github.<用户名>或者自己拥有的域名之一<verion>的标签必须是带SNAPSHOT的,例如1.0-SNAPSHOT,否则在release:prepare的时候会报错说没有可用的SNAPSHOT版本
确保信息正确以后,在pom.xml中加入
<profiles> <profile><id>release-sign-artifacts</id><activation> <property><name>performRelease</name><value>true</value> </property></activation><build> <plugins><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.1</version> <executions><execution> <id>sign-artifacts</id> <phase>verify</phase> <goals><goal>sign</goal> </goals></execution> </executions></plugin> </plugins></build></profile> </profiles>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution> </executions></plugin><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions><execution> <id>attach-javadocs</id> <goals><goal>jar</goal> </goals></execution> </executions></plugin> </plugins> </build>
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Repository</name> <url>http://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement>