Jil*_*urp 8 java nexus sonatype maven-plugin maven
我有几个github java项目.其中一个我已经手动部署到sonatype的存储库,以便它在maven中心发布.
这是一个有点痛苦的过程,因为它似乎涉及太多的箍以跳过和大量的手动工作,我想自动化.所以我实际上已经停止这样做,因为这只是太多的工作.有大量的文档表明这是可能的,并且相当多一些表明它以某种方式涉及使用nexus-staging-maven-plugin做一些事情.不幸的是,所有这些文档都是(以典型的maven风格)跳过基本细节,这使我能够以简单的方式找出允许我自动将发布版本自动发布到sonatype存储库所需的最少步骤(即没有我手动批准的东西).
那么,什么是我的pom中需要出现的模糊(假设一个标准的不复杂的java项目),包括sonatype存储库的url,我发现的所有文档似乎都坚持localhost:8081就是它,并且是必需的maven咒语让它做一个发布(最好通过mvn发布插件),让它签署工件,并让它将生成的工件部署到sonatype,批准并准备好同步到maven central等.
因此,我正在寻找在红宝石世界中替换"宝石推"的maven,它可以在一个方便的单行中完成工作.这是一个简单的例子,给出了一个我认可的jar文件,如何让它以最少量的大惊小怪结束在maven中心.
我非常感谢已经设置的pom文件的一些例子,我可以复制和改编.
这是我工作的pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jillesvangurp</groupId>
<artifactId>jsonj</artifactId>
<version>1.34-SNAPSHOT</version>
<name>JsonJ</name>
<description>A framework for working with json in Java the "proper" way. No mappings or model classes, it's all just lovely json, but in Java.</description>
<url>https://github.com/jillesvangurp/jsonj</url>
<licenses>
<license>
<name>MIT license</name>
<url>https://github.com/jillesvangurp/jsonj/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git://git@github.com:jillesvangurp/jsonj.git</url>
<connection>scm:git:git@github.com:jillesvangurp/jsonj.git</connection>
<developerConnection>scm:git:git@github.com:jillesvangurp/jsonj.git</developerConnection>
</scm>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<developers>
<developer>
<id>jillesvangurp</id>
<name>Jilles van Gurp</name>
<url>http://www.jillesvangurp.com</url>
<timezone>gmt+1</timezone>
<roles>
<role>Main Developer</role>
</roles>
</developer>
</developers>
<organization>
<name>www.jillesvangurp.com</name>
<url>http://jillesvangurp.com</url>
</organization>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>documentation</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>gathersource</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
<configuration>
<!-- The Base URL of Nexus instance where we want to stage -->
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<serverId>sonatype-nexus-staging</serverId>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<groupId>org.apache.maven.wagon</groupId>
<version>2.2</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>sonatype-oss-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</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>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.jillesvangurp</groupId>
<artifactId>efficientstring</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
下面的评论(@ aurelien-thieriot)让我走上了正确的轨道但本身还不够.
最后我拿了sonatype父pom并将它压平成我的pom文件.
这允许我正常使用mvn发布插件.它将工件上载到sonatype staging存储库.然后为了发布工件,我实际上需要staging存储库id.您可以从https://oss.sonatype.org/index.html#stagingRepositories中的存储库视图中找到它.
在我的情况下,命令行变为:
mvn nexus-staging:release -Ddescription="Release 1.33" -DstagingRepositoryId=comjillesvangurp-1002
Run Code Online (Sandbox Code Playgroud)
如果没有正确的ID,它就无法理解它仍然会失败:Sonatype Maven Staging Plugin Issue
所以95%自动化,但我仍然需要每次都找出stagingRepositoryId.
mvn release:perform实际上告诉你staging存储库的id.我猜你可以编写一个脚本,从输出中提取这个id,然后将其传递给下一步.如果有人知道某些mvn voodoo也可以进行mvn release:perform分段发布,那将非常感激.
为了方便 Maven 项目,Sonatype 提供了一个父 POM,您可以使用所有基本配置将其添加到项目中:
重要的部分是:
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
Run Code Online (Sandbox Code Playgroud)
以及源代码存储库详细信息:
<scm>
<connection>scm:svn:http://foo.googlecode.com/svn/trunk/</connection>
<developerConnection>scm:svn:https://foo.googlecode.com/svn/trunk/</developerConnection>
<url>http://foo.googlecode.com/svn/trunk/</url>
</scm>
Run Code Online (Sandbox Code Playgroud)
您还需要在您的计算机上安装 GPG(需要签署软件包)并settings.xml正确填写您的凭据:
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
Run Code Online (Sandbox Code Playgroud)
之后,您应该能够使用两步发布:
$ mvn release:prepare
$ mvn release:perform
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不知道有什么方法可以自动化流程的手动批准部分(在 oss.sonatype.org 中)。但这应该已经为您节省了一些时间。
如上所示,该文档可能有点复杂,但非常完整,并为您提供了各种场景所需的所有信息。
编辑:
事实上我认为我错了,有一部分是关于自动化审批流程的。有趣的。
对于这一部分,你是对的,细节非常有限。不过,我希望配置的第一部分已经对您有所帮助。我需要进一步研究这个分阶段的东西(或者也许其他人已经完成了!)
再次编辑:
我需要实际尝试一下,但听起来如下:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
<configuration>
<!-- The Base URL of Nexus instance where we want to stage -->
<nexusUrl>https://oss.sonatype.org/service/local/staging/deploy/maven2/</nexusUrl>
<serverId>sonatype-nexus-staging</serverId>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
根据文档,部署应该被正确的暂存工作流程(包括关闭)替换,并且它将保留最新步骤:
$ mvn nexus-staging:release -Ddescription="Yippie!"
Run Code Online (Sandbox Code Playgroud)
待测试...
| 归档时间: |
|
| 查看次数: |
3072 次 |
| 最近记录: |