这是我参与更文挑战的第13天,活动详情查看: 更文挑战java
[TOC]linux
maven项目的发布git
平时开发中都是使用别人的maven项目,做为一个标准的程序员发布个本身的程序也是必要的。程序员
其次,咱们须要在sonatype平台申请,若是有帐号就直接登陆sonatype登陆,没有的话在登陆界面也能够点击注册github
注册完帐号以后咱们能够登陆sonatype平台,开始建立工单apache
<groupId>com.github.zxhTom</groupId>
<artifactId>csdn-sdk</artifactId>
<version>1.0.0</version>
复制代码
属性值 | 属性解释 |
---|---|
Summary | 这就是项目说明,你直接能够写我的项目,搞个统称就行 |
Project URL | 你就填写你的github或者git.oschina.net 的,或者我的主页也行 |
SCM URL | 写成和Project URL 同样也没啥事 |
username | 用户名 |
这里须要特别说明的是 Group Id,若是你是托管在 Github 或者 Git@OSC 可使用 com.github.binarylei 或者 net.oschina.XXX,剩下的能够依照实际状况填写,例如托管的地址等等(托管地址等信息会在用去 maven 仓库搜索的时候显示,用来帮助用户找到你的项目地址寻求帮助)。另外此处填写的 groupId 必须和你要发布的组件的 pom 中的 groupIdd 同样,必须同样!!!windows
-----------------------------------漫长的等待-----------------------------------缓存
com.github.zxhTom
这个groupid我以前注册申请过,因此这里sonatype回复我不会再次给我建立工单,让我使用以前那个工单。下面来看看两张工单![oytmxyuek.bkt.clouddn.com/20181008005…]安全
![oytmxyuek.bkt.clouddn.com/20181008006…]markdown
![oytmxyuek.bkt.clouddn.com/20181008007…]
![oytmxyuek.bkt.clouddn.com/20181008008…]
下载好gpg以后咱们就傻瓜式安装,这里不细说
gpg --version
查看gpg安装是否成功
gpg --gen-key
生成公钥密钥gpg --list-keys
查看公钥 ; 其中pub那一长串就是咱们的就是咱们须要上传的公钥id,gpg的版本不一样所生成的pub id 格式和 长度不一样。咱们不用担忧passphrase
,这个passphrase
就是咱们的凭证,必定要记住gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 公钥ID
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 公钥ID
查看公网公钥<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<optimize>true</optimize>
<compilerArguments>
<verbose/>
<!-- 若是是linux构建须要将分号缓存冒号:, 若是是windows下则用分号 -->
<bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<configuration>
</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>
<version>2.7</version>
<configuration>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<!-- 容许子项目也是用该插件 -->
<aggregate>true</aggregate>
<!-- 因为如今该插件比较严谨,该标签是忽略严格验证。好比没有的标签注解能够忽略错误 -->
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
复制代码
oss-parent
oss-parent
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
复制代码
<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>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:https://gitee.com/zxhTom/csdnSdk.git</connection>
<developerConnection>scm:git:https://gitee.com/zxhTom/csdnSdk.git</developerConnection>
<url>https://gitee.com/zxhTom/csdnSdk</url>
<tag>${project.version}</tag>
</scm>
<developers>
<developer>
<name>zxhTom</name>
<email>870775401@qq.com</email>
<roles>
<role>developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
复制代码
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>Sonatype 帐号</username>
<password>Sonatype 密码</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>Sonatype 帐号</username>
<password>Sonatype 密码</password>
</server>
</servers>
复制代码
ps : 这种方式笔者一开始没有采纳,因此没有亲测,可是下面一种方法是我按照第一种变形的。因此这一种应该是能够的。 剩下的咱们就能够mvn clean deploy 进行发布了。发布的过程须要输入gpg passphrase验证。这里只是配置。真正发布下面继续。
![./maven发布/019.png]
<profile>
<id>default_maven</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>CentralRepository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
复制代码
到这里基本结束了。由于maven发布须要加解密,上面咱们使用gpg加密,这里须要将gpg的信息配置成一个profile,这样mvn deploy的时候就知道gpg了。这时候配置须要用到以前在发布gpg公钥的时候我让你们记住的东西了passphrase
。下图被打马赛克的就是个人passphrase
这里配置了,根据版本不同 有的是gpg , 有的是gpg2 . 读者两个分别试试就知道本身版本适合哪个了
maven也是默认读取这个地址的(远程中央仓库)
<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>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>zxhTom</name>
<email>870775401@qq.com</email>
<roles>
<role>developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<scm>
<connection>scm:git:https://gitee.com/zxhTom/csdnSdk.git</connection>
<developerConnection>scm:git:https://gitee.com/zxhTom/csdnSdk.git</developerConnection>
<url>https://gitee.com/zxhTom/csdnSdk</url>
<tag>${project.version}</tag>
</scm>
<repositories>
<repository>
<id>maven-central</id>
<name>maven-central</name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
复制代码
惟一不一样的是,此种方法多了distributionManagement。 distributionManagement中的repository和snapshotRepository中的id必定要和settings中server的id保持一致
这也是为何第一种方法中server须要配置两条,由于oss-parent中的distributionManagement两个id不一样。而咱们自定义的就能够定义一致。咱们的settings中就能够只配置一个server了。
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>Maven Central Staging
Repository
</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
复制代码
好了,前期的准备工做已经完成了。那么如今咱们开始配置咱们项目和maven就能够发布到中央仓库了。
执行mvn clean deploy 。 我是在idea中执行的 由于gpg已经配置在settings.xml中了,因此后面不用跟gpg信息了。
执行完咱们就能够在https://oss.sonatype.org
中查看咱们刚发布的项目了,此时尚未发布到中央仓库;登陆此网站帐号密码就是sonatype的。左侧build promotion->staging repositories中列表最底下就是应该是咱们发布的项目
close的时候须要看信息,close失败会在activity中提示你哪些错误的。还有些pom细节这里不能细说了,时间问题