這是我參與更文挑戰的第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細節這裏不能細說了,時間問題