向maven中央仓库提交jar

  • 作者: 凯哥Java(公众号:凯哥Java)
  • 网络文章
  • 时间:2018-08-09 17:21
  • 3677人已阅读
简介 从来都是从中央仓库下载jar,这次需要向中央仓库提交jar,利用SonatypeOSSRH可以把jar等资源提交给Maven的中央仓库。SonatypeOSSRH介绍:SonatypeOSSRH使用Nexus 为开源项目提供仓库管理服务,该仓库就是所谓maven的中央仓库,OSSRH允许我们向Maven中央仓库提交二进制文件。1:提交(deploy)开发版本的二进制文件(snapshor

🔔🔔好消息!好消息!🔔🔔

 如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号代升级ChatGPT4

有需要的朋友👉:微信号 kaigejava2022

从来都是从中央仓库下载jar,这次需要向中央仓库提交jar, 利用Sonatype OSSRH可以把jar等资源提交给Maven的中央仓库。

Sonatype OSSRH介绍:

Sonatype OSSRH使用Nexus 为开源项目提供仓库管理服务,该仓库就是所谓maven的中央仓库,OSSRH允许我们向Maven中央仓库提交二进制文件。

1:提交(deploy)开发版本的二进制文件(snapshorts)

2: 阶段性的发布版本

3:发布一个release,然后同步他们到中央仓库。

初始阶段

1:注册一个JIRA账号:https://issues.sonatype.org/secure/Signup!default.jspa

2:创建一个新工程的单:https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

只有当这个jira单的状态我resolved时,才可以提交jar包

审查要求

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


TopTop