zoukankan      html  css  js  c++  java
  • 向maven中央仓库提交jar

    从来都是从中央仓库下载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

    原文:向maven中央仓库提交jar

    相关:

    上传Android或Java库到Maven central repository

    发布Maven构件到中央仓

  • 相关阅读:
    数据探索
    String的相关操作总结
    2015/6/10 按位运算 补码求法
    15年6月8号 jsp内置对象总结
    投资小故事
    定投出来的千万富翁
    股票PE的应用
    幸福人生的资产配置
    定投6年,以亏损收场,她到底做错了什么?
    一则故事让你轻松了解保险的实质
  • 原文地址:https://www.cnblogs.com/langtianya/p/5930297.html
Copyright © 2011-2022 走看看