Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Github Action to publish jar to Maven central warehouse

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to use Github Action to release jar to Maven central warehouse", the content is detailed, the steps are clear, and the details are handled properly. I hope this "how to use Github Action to release jar to Maven central warehouse" article can help you solve your doubts.

Github Action

Github Action is a CI/CD service created by Github. Its goal is to make it easy to automate all software development workflows. Build, test, and deploy code directly from GitHub. CI (continuous integration) consists of many operations, such as code merging, running tests, logging in to remote servers, publishing to third-party services, and so on.

Expected effect

When the contemporary codebase releases Release (release), it triggers the effect of publishing the branches contained in Release to the central repository of Maven.

Expand reading:

Release (release) is a first-level object with Changelogs (change log) and binaries that can represent all project history up to a specific point in time beyond the Git schema itself.

prerequisite

On how to publish the project to the Maven central warehouse and some of the necessary conditions will not be discussed here, there are many tutorials online, interested can search. You can also refer to Payment Spring Boot's pom.xml. Here are just a few key points that you need to:

OSSRH account.

GPG key information.

Note: both of these sensitive data should not be leaked to others, or your project may be controlled by others.

Github Action Secrets

In order to publish from Github Action, we need to make our GPG private key and OSSRH user information available to Github Action. To keep this sensitive information secure, we can use Github Action Secrets to store it.

Details supplement of GPG

The GPG_PASSWORD here is GPG's Passphrase, which will definitely be mentioned in the online Maven Central Warehouse tutorial. I won't go into details here. It should be noted that the public key must be uploaded to the public key server.

The steps to obtain GPG_SECRET are as follows:

Make sure you have a GPG environment and configure the GPG key pair according to other tutorials.

Execute gpg-- list-secret-keys to view the Key list and copy the ID you need

[root@192] # gpg-- list-secret-keys/root/.gnupg/pubring.kbx----sec rsa2048 2020-07-27 [SC] 8AC0AB86C34ADC6ED110A5A9E6730F4374866065uid felord (felord) dax@felord.cn

Execute gpg-a-- export-secret-keys KEY_ID (KEY_ID is a string starting with 8AC0AB in the figure above) to export the private key. Here, you need to enter a password (GPG_PASSWORD) to protect the private key. Then the following ciphertext appears:

-BEGIN PGP PRIVATE KEY BLOCK----. Ciphertext area.-END PGP PRIVATE KEY BLOCK-

This is ``GPG_SECRET.

Modify the POM of the project

Then modify the pom.xml file of the project. I have already proposed the template, and I have written notes on the areas that cannot be modified:

Cn.felord payment-spring-boot 1.0.9.RELEASE pom 4.0.0 payment-spring-boot wechat-pay and alipay sdk https://github.com/NotFound403/payment-spring-boot Apache License Version 2.0 https://www.apache.org/licenses/LICENSE-2.0.txt repo A business-friendly OSS license felord felord@qq.com felord.cn payment-spring-boot-1.0.9.RELEASE https://github.com/NotFound403/payment- Spring-boot scm:git: https://github.com/NotFound403/payment-spring-boot.git scm:git: https://github.com/NotFound403/payment-spring-boot.git deploy org.apache.maven.plugins Maven-source-plugin org.apache.maven.plugins maven-javadoc-plugin org.apache.maven.plugins Maven-gpg-plugin payment-spring-boot-autoconfigure payment-spring-boot-starter 1.8 1.8 UTF-8 UTF-8 1.8 2.4.2 4.10.167.ALL 1.0 .0.RELEASE 1.18.12 2.9.10 1.66 2.11.4 4.5.13 ossrh Nexus Release Repository https://oss.sonatype.org/service/local/staging/deploy/maven2 sonatype-nexus-snapshots Nexus Snapshot Repository Https://oss.sonatype.org/content/repositories/snapshots org.apache.maven.plugins maven-source-plugin 3.1.0 Package jar-no-fork Org.apache.maven.plugins maven-javadoc-plugin 3.2.0 private true UTF-8 Compile jar Org.apache.maven.plugins maven-gpg-plugin 1.6 sign-artifacts verify Sign-pinentry-mode loopback Org.sonatype.plugins nexus-staging-maven-plugin 1.6.8 true Ossrh https://oss.sonatype.org/ false org.sonatype.plugins nexus-staging-maven-plugin

Make the necessary fills in combination with your own project.

Write Github Action scripts

The Github Action script is saved in the .GitHub / workflows path under the root of the project. We only need to write a yaml to declare the steps to be executed. For specific syntax, you can see the relevant Chinese documents. Here, only the action scripts published to the Maven central repository are listed:

# an event equivalent to a statement of script use: name: Maven Central Repo Deployment# triggers the script here for the on: release: types: [released] # defines a release task jobs: publish:# task running environment runs-on: ubuntu-latest# task step steps:# 1. Declare the checkout repository code to the workspace-name: Checkout Git Repo uses: actions/checkout@v2# 2. The parameters that will be used to install the Java environment are those configured in Git Action secrets. The value of # should be preceded by secrets. Key. -name: Set up Maven Central Repo uses: actions/setup-java@v1 with: java-version: 1.8 server-id: sonatype-nexus-staging server-username: ${secrets.OSSRH_USER}} server-password: ${{secrets.OSSRH_PASSWORD}} gpg-passphrase: ${{secrets.GPG_PASSWORD}} # 3. Post to Maven Central Warehouse-name: Publish to Maven Central Repo# here using action scripts written by others, you can see his documentation for details. Uses: samuelmeuli/action-maven-publish@v1 with: gpg_private_key: ${{secrets.GPG_SECRET}} gpg_passphrase: ${{secrets.GPG_PASSWORD}} nexus_username: ${{secrets.OSSRH_USER}} nexus_password: ${{secrets.OSSRH_PASSWORD}} trigger Action

After all the preparations are completed, the action script will be submitted to Github. When you use the release feature, the entire publishing process will be automatically executed in the action column:

After reading this, the article "how to use Github Action to publish jar to Maven Central Warehouse" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report