在Maven中央存储库中发布github项目

This tutorial is for project developers who would like to promote their work by publishing their artifacts in the Maven Central Repository.

本教程适用于希望通过在Maven中央存储库中发布其工件来促进其工作的项目开发人员。

Let’s begin:

让我们开始:

You can review steps from Maven Official Guide Page but this tutorial is a smaller version of the guide.

您可以从《 Maven官方指南》页面中查看步骤,但是本教程是该指南的较小版本。

Firstly, make sure the following criteria are met:

首先,请确保满足以下条件:

  1. No project dependencies are missing in your pom.xml

    pom.xml中没有缺少项目依赖项
  2. There are no errors in your project when you execute the mvn compile command

    执行mvn compile命令时,项目中没有错误。

  3. There are no unit test failures in your project when you execute the mvn test command

    执行mvn test命令时,项目中没有单元测试失败

在Maven中央存储库中为项目创建存储库(Creating a Repository for your project in Maven Central Repository)

Create a JIRA account: Create a JIRA account if you don’t have one from here.

创建一个帐户JIRA:创建JIRA帐户,如果你没有一个来自这里

Create a New Project JIRA ticket: Create a new project ticket from here. Make sure the domain you use for the group id of your project is accessible as the JIRA assignee of your ticket will ask you to verify it. Sample ticket: OSSRH-60335. Once your ticket is raised, you can wait as someone needs to be assigned to it and take action.

创建新项目JIRA票证:此处创建新项目票证。 确保用于项目组ID的域可访问,因为故障单的JIRA受让人将要求您进行验证。 样本票: OSSRH-60335 。 票证一旦升起,您就可以等待,因为有人需要分配给它并采取行动。

NOTE: Wait for the ticket to be resolved before releasing the project.

注意:在发布项目之前,请等待票证解决。

通过GnuPG设置文件签名 (Setting up file signing through GnuPG)

Install GnuPG: Install GnuPG from here if not already present in your machine. You can verify if it is already installed in your machine or not through the following command:

安装GnuPG:如果您的机器尚不存在,请从此处安装GnuPG。 您可以通过以下命令来验证它是否已经安装在您的计算机中:

gpg --version

Or

要么

gpg2 --version

If it is installed, the command will provide you with a version number.

如果已安装,该命令将为您提供版本号。

NOTE: While setting this up, you may be asked for a passphrase, enter a new passphrase and note it down somewhere so that you do not forget it.

注意:进行此设置时,可能会要求您输入密码,输入新的密码并将其记在某个地方,以免您忘记密码。

Setup GnuPG Keys: Now, GPG keys in your machine which will help you to sign your artifacts that you would like to upload to Maven Central. Depending on whether you have gpg or gpg2 installed, the next few commands will be of the form gpg* or gpg2*. To generate keys, execute the following command:

设置GnuPG密钥:现在,机器中的GPG密钥将帮助您签名要上传到Maven Central的工件。 根据您是否安装了gpggpg2 ,接下来的几个命令的形式为gpg *gpg2 * 。 要生成密钥,请执行以下命令:

gpg --gen-key

Once executed, check the keys generated with the following command:

一旦执行,请检查使用以下命令生成的密钥:

gpg --list-keys

The keys will be listed in the following format:

键将以以下格式列出:

/home/juven/.gnupg/pubring.gpg
------------------------------
pub 1024D/C6EED57A 2010-01-13
uid Juven Xu (Juven Xu works at Sonatype) <juven@sonatype.com>
sub 2048g/D704745C 2010-01-13

Now, you need to distribute your generated public key to the keyserver. You can use the following command and the first key that was shown in the previous command:

现在,您需要将生成的公共密钥分发到密钥服务器。 您可以使用以下命令以及上一个命令中显示的第一个键:

gpg --keyserver hkp://pool.sks-keyservers.net --send-keys C6EED57A

To verify whether it was been sent without errors, execute the following command to receive the key:

要验证是否已正确发送它,请执行以下命令以接收密钥:

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys C6EED57A

NOTE: At the time of publishing your artifact, if you get an error saying that the key is not found in some ‘X’ server, execute the send-keys command again to the mentioned server.

注意:在发布工件时,如果收到错误消息,指出在某些“ X”服务器中找不到密钥,请再次对上述服务器执行send-keys命令。

Now, it is time to set up your pom.xml so that it can communicate and upload your artifacts to the Maven Central Repository.

现在,是时候设置pom.xml以便它可以通信并将工件上传到Maven中央存储库了。

设置您的pom.xml (Setting up your pom.xml)

Ensure all project-related metadata are provided in your pom.xml: The pom.xml firstly needs the groupId, artifactId, and version. Make sure that the groupId and the artifactId are the same as that in the JIRA ticket you created.

确保在pom.xml中提供了所有与项目相关的元数据: pom.xml首先需要groupId,artifactId和版本。 确保groupId和artifactId与您创建的JIRA故障单中的相同。

<groupId>com.github.kunalk16</groupId>    <artifactId>lightExcelReader</artifactId>    <version>1.0.1</version>

Also, provide some details about your project. These details will be displayed in Maven Central once the release is done.

另外,提供有关您的项目的一些详细信息。 发布完成后,这些详细信息将显示在Maven Central中。

<name>Light Excel Reader</name>
<description>A lightweight Java framework to read .xlsx excel files.</description>
<url>https://github.com/kunalk16/lightExcelReader</url>

Add license information: Add the license information to your pom.xml. Sample MIT license can be represented in the following way:

添加许可证信息:将许可证信息添加到pom.xml。 可以通过以下方式表示示例MIT许可证:

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>

Other licenses can also be added. More information can be found here.

也可以添加其他许可证。 在这里可以找到更多信息。

Add developer information: Developer information needs to be added to your pom.xml. Sample:

添加开发者信息:开发者信息需要添加到您的pom.xml中。 样品:

<developers>
<developer>
<name>Kunal Karmakar</name>
<email>your_email@gmail.com</email>
<organization>com.github.kunalk16</organization>
<organizationUrl>https://www.github.com/kunalk16/lightExcelReader</organizationUrl>
</developer>
</developers>

Add SCM information: The details of the repository for the source code needs to be added. For GitHub, the following format can be used:

添加SCM信息:需要添加源代码存储库的详细信息。 对于GitHub,可以使用以下格式:

<scm>
<connection>scm:git:git://github.com/kunalk16/lightExcelReader.git</connection>
<developerConnection>scm:git:ssh://github.com:kunalk16/lightExcelReader.git</developerConnection>
<url>https://www.github.com/kunalk16/lightExcelReader</url>
</scm>

For other repositories, details can be found here.

对于其他存储库,可以在此处找到详细信息。

Add distribution management details: The following format can be used:

添加分发管理详细信息:可以使用以下格式:

<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>

Add deployment and release plugins: All the following plugins are required for the deployment and release into Maven Central Repository:

添加部署和发布插件:部署和发布到Maven Central存储库中需要以下所有插件:

<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</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-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>
<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>
</plugins>
</build>

Your complete pom.xml should look somewhat like this:

您完整的pom.xml应该看起来像这样:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>com.github.kunalk16</groupId>
<artifactId>lightExcelReader</artifactId>
<version>1.0.1</version><name>Light Excel Reader</name>
<description>A lightweight Java framework to read .xlsx excel files.</description>
<url>https://github.com/kunalk16/lightExcelReader</url><licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses><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><developers>
<developer>
<name>Kunal Karmakar</name>
<email>your_email@gmail.com</email>
<organization>com.github.kunalk16</organization>
<organizationUrl>https://www.github.com/kunalk16/lightExcelReader</organizationUrl>
</developer>
</developers><scm>
<connection>scm:git:git://github.com/kunalk16/lightExcelReader.git</connection>
<developerConnection>scm:git:ssh://github.com:kunalk16/lightExcelReader.git</developerConnection>
<url>https://www.github.com/kunalk16/lightExcelReader</url>
</scm><properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties><dependencies>
<!-- your project dependencies here -->
</dependencies><build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</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-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>
<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>
<!-- Any other plugins that your need here -->
</plugins>
</build>
</project>

设置您的settings.xml: (Setting up your settings.xml:)

Look out for maven’s .m2 folder if you have an existing settings.xml file. Create one if is not present.

如果您已有一个settings.xml文件,请查找maven的.m2文件夹。 如果不存在,则创建一个。

Add JIRA credentials: JIRA credentials need to be added to your settings.xml file in the following format.

添加JIRA凭据: JIRA凭据需要以以下格式添加到settings.xml文件中。

<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>

Add GPG passphrase to your settings.xml: Add your passphrase from the GPG setup step to your settings.xml file. This is required for signing your artifacts during upload. Sample:

将GPG密码添加到您的settings.xml:将密码从GPG设置步骤添加到settings.xml文件。 这是在上传过程中对工件进行签名所必需的。 样品:

<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>the_pass_phrase</gpg.passphrase>
</properties>
</profile>
</profiles>

The completed settings.xml file should look somewhat like this:

完成的settings.xml文件应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>the_pass_phrase</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>

在Maven中央存储库中发布项目: (Releasing your project in Maven Central Repository:)

Once you have completed your setup for GnuPG, pom.xml, and settings.xml, ensure that all the details provided are correct.

完成GnuPG,pom.xml和settings.xml的设置后,请确保提供的所有详细信息都是正确的。

Snapshot Deployment:

快照部署:

Now, change your project version to something like this:

现在,将项目版本更改为以下内容:

<version>1.0-SNAPSHOT</version>

This is required because we will first try a snapshot deployment of your project. After the version is modified, run the following:

这是必需的,因为我们将首先尝试对您的项目进行快照部署。 修改版本后,运行以下命令:

mvn clean deploy

The successful execution of this command will show your project here.

成功执行此命令将在此处显示您的项目。

Release Deployment:

发布部署:

Execute the following command to modify the version of your project to the required release version:

执行以下命令,将项目的版本修改为所需的发行版本:

mvn versions:set -DnewVersion=1.0.0

Now, release the project using the following command:

现在,使用以下命令释放项目:

mvn clean deploy -P release

Successful execution should upload your project artifacts in Maven Central Repository. You can then search for your repository here. After some hours, it will even be available in the Maven Repository site.

成功执行后,应将项目工件上传到Maven Central信息库。 然后,您可以在此处搜索存储库。 几个小时后,它甚至可以在Maven Repository网站上找到

NOTE: If release deploy command execution was successful and your repository does not come up in the search, wait for some time. It may take some hours to reflect but it will do so provided your command was successfully executed.

注意:如果发布部署命令执行成功并且您的存储库没有出现在搜索中,请等待一段时间。 可能需要几个小时才能反映出来,但前提是您的命令已成功执行。

If you face any issues, you can search with the error message in google, there will be someone who has faced your issue along with a StackOverflow post or an issue in JIRA itself.

如果您遇到任何问题,可以在Google中搜索错误消息,然后有人会与您的问题以及StackOverflow帖子或JIRA本身的问题一起出现。

On successful completion, your project should come up in Maven Central Repository like this. It should also show up in the Maven Repository site like this.

成功完成后,您的项目应该像这样在Maven Central Repository中启动。 它也应该像这样显示在Maven Repository网站中。

Do not forget to place your Maven Central Badge in your source code repository’s README.md file like this!!! ✌️

不要忘记将你的Maven中央徽章在喜欢你的源代码库的README.md文件这个! ✌️

翻译自: https://medium.com/@kkdthunlshd/publish-github-project-in-maven-central-repository-bdf0e5aa2b82

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值