笔者最近自己开发了一个开源项目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>
这个profile在运行mvn release:perform的时候生效,主要作用是为发布的软件做数字签名以防别人下载到被修改过的软件。
在pom.xml文件中继续添加:
<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>
由于提交到Maven Central Repository的开源软件需要有对应的sources.jar和javadoc.jar文件,因此添加这两个插件方便自动生成这两个必须的文件。
继续修改pom.xml文件,添加:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Repository</name>
<url>http://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
这个是发布软件时的目标仓库,如果你发布的不是Sonatype Nexus,那么URL要作相应修改。
到这里pom.xml文件就修改完了。接下来进行其他步骤。请点击
http://drug.iteye.com/blog/1979777查看第二篇。
分享到:
相关推荐
Maven仓库 该项目将以Maven存储库的形式发布TeamVK公开发布的Java资源。 如何使用 为了使用此Maven存储库,您可以使用各种插件(用于您的构建系统,例如Gradle和... mavenCentral() github("teamvk", "maven-repositor
Maven artifact is available from maven central repository. Just add dependency in your pom.xml: org.jamel.dbf dbf-reader 0.0.3 Supported fields types DBF field type Returned as character ...
Use the jcenter() or mavenCentral() repository. repositories { jcenter() mavenCentral() } Then pick a module. Core dependencies { implementation ...
Maven发布动作GitHub Action用于自动发布Maven软件包总览这个动作执行Maven deploy生命周期阶段为Maven提供您的GPG密钥和密码,以便您可以使用maven-gpg-plugin对工件进行签名向Maven提供您的Nexus凭据,以便它可以...
Some modules of project contain dependencies not included in Maven Central - to build such modules you need first install these dependencies in your local repository. To do this, please, download ...
Prebuilt JARs are available from the central Maven repository or the Sonatype Maven repository. Alternatively, you can get the latest code from Git and build it yourself: git clone git://github....
Build Status ... Changelog See what is new in version 1.4.9 released on 19th September... mavenCentral() } } dependencies { compile 'com.loopj.android:android-async-http:1.4.9' } development snapshots ...
mavenCentral() } allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } mavenCentral() } } 依赖项{实现'com.github.gyadministrator:CustomDownSelect:1.2'} Maven...
Linux Redis嵌入式服务器用于Java集成测试Maven依赖Maven Central: < dependency> < groupId>com.github.kstyrc</ groupId> < artifactId>embedded-redis</ artifactId> < version>0.6</ version></ dependency> ...
我们在Maven Central中有一个发布库,但其中存在该版本,因此不会经常更新。 因此,我建议使用来获取最新发行版本(例如master分支或可用标签)。 有关如何包括依赖项的说明,请单击上面的链接或作为Maven项目的...
@Test 运行一个 docker 容器如何启用存储库(一旦我有实际发布,我会考虑 maven central) <repository> <id>jitpack.io</id> <url>https://jitpack.io</url></repository>添加依赖 <dependency> <groupId>...
central 之前就可以使用了。 参考 Maven 将以下内容添加到 pom.xml: < repositories > < repository > < id >jitpack.io</ id > < url >https://jitpack.io</ url > </ repository > </ ...
central 之前就可以使用了。 参考 Maven 将以下内容添加到 pom.xml: < repositories > < repository > < id >jitpack.io</ id > < url >https://jitpack.io</ url > </ repository > </ ...
# Maven Central git clone https://github.com/CSTARS/gwt-esri.git # install gwt-esri into your local repository first cd gwt-esri mvn install # if this didn't fail then built/package up this exam
NavigationTabStrip 导航选项卡条具有平滑的交互作用。 您可以在检查示例应用程序。 警告 This library is not more supported.... mavenCentral() maven { url ' http://dl.bintray.com/gigamole/maven
SlideImageView 简单方便的库,使您可以在视图中滑动图像。 您可以在检查示例应用程序。 警告 This library is not more supported.... mavenCentral() maven { url ' http://dl.bintray.com/gigamole/maven
预览版本您可能想要访问新功能,而又不想等到Maven Central上发布了稳定的版本。 在这种情况下,您可以从获得最新的开发版本。 您所需pom.xml就是将以下内容放入pom.xml : < repositories> < repository> < id>...
The JAR files for specific child modules or platforms can also be obtained individually from the Maven Central Repository. We can also have everything downloaded and installed automatically with: ...