歷來都是從中央倉庫下載jar,此次須要向中央倉庫提交jar, 利用Sonatype OSSRH能夠把jar等資源提交給Maven的中央倉庫。java
Sonatype OSSRH介紹:git
Sonatype OSSRH使用Nexus 爲開源項目提供倉庫管理服務,該倉庫就是所謂maven的中央倉庫,OSSRH容許咱們向Maven中央倉庫提交二進制文件。github
1:提交(deploy)開發版本的二進制文件(snapshorts)apache
2: 階段性的發佈版本jsp
3:發佈一個release,而後同步他們到中央倉庫。maven
1:註冊一個JIRA帳號:https://issues.sonatype.org/secure/Signup!default.jspaui
2:建立一個新工程的單:https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134url
只有當這個jira單的狀態我resolved時,才能夠提交jar包spa
1:提供javadoc和source插件
2: 使用gpg或者pgp對文件進行簽名
3: pom.xml文件
4:正確的座標:groupId,artifactId,version
<groupId>com.sequoiadb</groupId> <artifactId>sequoiadb-driver</artifactId> <version>1.12</version>
5: projectName,description,url等。
<name>${project.groupId}:${project.artifactId}</name> <description>SequoiaDB Driver Library</description> <url>https://github.com/SequoiaDB/SequoiaDB</url>
6: license 信息
<licenses> <license> <name>The Apache License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses>
7 : 開發者信息
<developers> <developer> <name>linyoubing</name> <email>linyoubing@sequoiadb.com</email> <organization>sequoiadb</organization> <organizationUrl>http://www.sequoiadb.com</organizationUrl> </developer> </developers>
8: SCM信息
<scm> <connection> scm:git:https://github.com/SequoiaDB/SequoiaDB.git </connection> <developerConnection> scm:git:https://github.com/SequoiaDB/SequoiaDB.git </developerConnection> <url>https://github.com/SequoiaDB/SequoiaDB</url> <tag>v1.12</tag> </scm>
能夠使用多種方式部署,這是使用maven的方式
1:分佈管理和認證:
我使用了maven部署插件,因此pom.xml中加入:
<distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> <repository> <id>ossrh</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement>
須要在maven_home/conf/settings.xml配置jira的帳號和密碼
<settings> <servers> <server> <id>ossrh</id> <username>your-jira-id</username> <password>your-jira-pwd</password> </server> </servers> </settings>
2:配置生成javadoc和sources包的插件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <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.9.1</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>
3:GPG自動簽名的插件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin>
在settings.xml中配置gpg的簽名 :(須要先用gpg來生成)
<settings> <profiles> <profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg2</gpg.executable> <gpg.passphrase>the_pass_phrase</gpg.passphrase> </properties> </profile> </profiles> </settings>
4: 使用Profile
應該javadoc和source的jar包生成也須要使用gpg來簽名,因此很浪費時間,並且這些執行一般都獨立於標準構建流程,因此把他們移動到一個profile.
<profiles> <profile> <id>release</id> <build> <plugins> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.3</version> <extensions>true</extensions> <configuration> <serverId>ossrh</serverId> <nexusUrl>https://oss.sonatype.org/</nexusUrl> <autoReleaseAfterClose>true</autoReleaseAfterClose> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5</version> <configuration> <autoVersionSubmodules>true</autoVersionSubmodules> <useReleaseProfile>false</useReleaseProfile> <releaseProfiles>release</releaseProfiles> <goals>deploy</goals> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <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.9</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
提交一個snapshot版本:
1:修改version加一個-SNAPSHOT, 執行 mvn clean deploy
發佈一個release版本
1:修改version 不要加-SNAPSHOT, 能夠手動修改,也能夠執行
mvn versions:set -DnewVersion=1.2.3
2: 執行 mvn clean deploy -P release