CI/CD 도구 Github Action 을 사용 하여 Maven 중앙 창고 에 대한 자세 한 설명 을 발표 합 니 다.
mvn deploy
.CI/CD 가 유행 하 는 오늘날 에 이런 방식 을 사용 하 는 것 은 약간'원시 적'입 니 다.그래서 저 는 일관 작업 을 지원 할 수 있 는 발표 도 구 를 찾 고 있 습 니 다.합병 코드 를 진행 할 때 자동 으로 구축 발 표를 촉발 할 수 있 습 니 다.이 를 할 수 있 는 무료 제품 이 있다.바로 Github Action 이다.Github Action
Github Action 은 Github 이 만 든 CI/CD 서비스 다.그것 의 목적 은 모든 소프트웨어 개발 작업 절차 의 자동 화 를 쉽게 하 는 것 이다.GitHub 에서 코드 를 직접 구축 하고 테스트 하 며 배치 합 니 다.CI(지속 적 통합)는 코드 통합,테스트 실행,원 격 서버 로그 인,제3자 서비스 발표 등 여러 가지 조작 으로 구성 된다.
오늘 은 Github Action 으로Payment Spring Boot를 Maven 중앙 창고 에 발표 해 보 겠 습 니 다.
기대 효과
현대 코드 라 이브 러 리 가 Release(발행 판)를 발표 할 때 Release 에 포 함 된 가 지 를 Maven 중앙 창고 에 발표 하 는 효 과 를 촉발 합 니 다.
확장 읽 기:
Release( )
는Changelogs
(로그 변경)과 바 이 너 리 파일 을 가 진 1 급 대상 으로 Git 구조 자체 의 특정한 시간 대 이전의 모든 프로젝트 의 역 사 를 나 타 낼 수 있다.전제 조건
프로젝트 가 Maven 중앙 창고 에 어떻게 발표 되 는 지 와 필요 한 조건 에 대해 서 는 더 이상 토론 하지 않 습 니 다.인터넷 에 많은 튜 토리 얼 이 있 으 니 관심 있 는 것 은 검색 해 보 세 요.Payment Spring Boot의
pom.xml
도 참고 할 수 있다.여기 서 중요 한 점 만 말씀 드 리 겠 습 니 다.필요 합 니 다.Github Action Secrets
Github Action 에서 발표 하기 위해 서 는 Github Action 이 우리 의 GPG 비밀 키 와 OSSRH 사용자 정 보 를 사용 할 수 있 도록 해 야 합 니 다.이러한 민감 한 정보의 안전성 을 확보 하기 위해 서 우 리 는Github Action Secrets을 사용 하여 그것들 을 저장 할 수 있다.
GPG 의 세부 사항 보충
이곳 의
GPG_PASSWORD
은 GPGPassphrase
이 고 인터넷 Maven 중앙 창고 튜 토리 얼 은 반드시 이것 을 언급 할 것 이다.여 기 는 더 이상 자세히 말 하지 않 겠 다.주의해 야 할 것 은 공개 키 는 반드시 공개 키 서버 를 업로드 해 야 한 다 는 것 이다.GPG_SECRET
획득 절 차 는 다음 과 같다.gpg --list-secret-keys
키 목록 을 보고 필요 한 ID 복사
[root@192 ~]# gpg --list-secret-keys
/root/.gnupg/pubring.kbx
------------------------
sec rsa2048 2020-07-27 [SC]
8AC0AB86C34ADC6ED110A5A9E6730F4374866065
uid felord (felord) [email protected]
실행gpg -a --export-secret-keys KEY_ID
KEY_ID
은 위의 그림 에서8AC0AB
로 시작 하 는 문자열)로 비밀 키 를 내 보 냅 니 다.비밀 키 를 보호 하 는 비밀 번 호 를 입력 해 야 합 니 다GPG_PASSWORD
.그리고 다음 과 같은 비밀문서 가 나 옵 니 다.
-----BEGIN PGP PRIVATE KEY BLOCK----
............ .............
-----END PGP PRIVATE KEY BLOCK-----
이게 바로'GPG'입 니 다.SECRET
。항목 의 POM 수정
그리고 항목 의
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">
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.9.RELEASE</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
<name>payment-spring-boot</name>
<description>wechat-pay and alipay sdk</description>
<url>https://github.com/NotFound403/payment-spring-boot</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<developers>
<developer>
<name>felord</name>
<email>[email protected]</email>
<organization>felord.cn</organization>
</developer>
</developers>
<scm>
<tag>payment-spring-boot-1.0.9.RELEASE</tag>
<url>https://github.com/NotFound403/payment-spring-boot</url>
<connection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</connection>
<developerConnection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</developerConnection>
</scm>
<profiles>
<!-- Deployment profile (required so these plugins are only used when deploying) -->
<!-- -->
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- GPG plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<modules>
<module>payment-spring-boot-autoconfigure</module>
<module>payment-spring-boot-starter</module>
</modules>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot.version>2.4.2</spring-boot.version>
<aliy-pay-sdk.version>4.10.167.ALL</aliy-pay-sdk.version>
<oss-starter.version>1.0.0.RELEASE</oss-starter.version>
<lombok.verison>1.18.12</lombok.verison>
<jackson.version>2.9.10</jackson.version>
<bcprov.version>1.66</bcprov.version>
<jackson.version>2.11.4</jackson.version>
<httpclient.version>4.5.13</httpclient.version>
</properties>
<!-- -->
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencyManagement>
<dependencies>
<!-- -->
</dependencies>
</dependencyManagement>
<!-- -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<!-- Prevent `gpg` from using pinentry programs -->
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
당신 의 프로젝트 와 결합 하여 필요 한 충전 을 하 세 요.Github Action 스 크 립 트 작성
Github Action
스 크 립 트 는 프로젝트 루트 디 렉 터 리 의.github/workflows
경로 에 저 장 됩 니 다.실행 절 차 를 설명 하기 위해 서yaml
만 작성 하면 됩 니 다.구체 적 인 문법 은 관련 중국어 문 서 를 볼 수 있 습 니 다.Maven 중앙 창고 에 발 표 된 action 스 크 립 트 만 보 여 줍 니 다.
#
name: Maven Central Repo Deployment
# release
on:
release:
types: [released]
#
jobs:
publish:
#
runs-on: ubuntu-latest
#
steps:
# 1. checkout
- name: Checkout Git Repo
uses: actions/checkout@v2
# 2. Java Git Action secrets ,
# key secrets.
- 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. Maven
- name: Publish to Maven Central Repo
# action , 。
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 }}
트리거 액 션준비 가 완료 되면 action 스 크 립 트 는 Github 에 제출 합 니 다.
release
기능 을 사용 하면 자동 으로action
란 에서 전체 발표 절 차 를 실행 합 니 다.이런 방식 은 한 번 에 설정 하여 곳곳에서 발표 된다.우 리 는 발표 에 더 이상 관심 을 가 질 필요 가 없다.언제 발표 할 지 에 만 관심 을 가 져 야 한다.
Payment Spring Boot 프로젝트 를 참고 할 수 있 습 니 다.
총결산
오늘 은 Github Action 에 대한 간단 한 사용 을 통 해 CI/CD 의 역할 을 소개 했다.이 기술 체 계 는 프로젝트 통합 납품 의 추세 이자 면접 에서 하 이 라이트 기능 이다.그리고 이런 방식 은'한 번 의 배치,언제 어디서나 통합 배치'를 실현 할 수 있다.
CI/CD 도구 Github Action 을 사용 하여 jar 를 Maven 중앙 창고 에 게시 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 발표 jar Maven 중앙 창고 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 부탁드립니다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Android Studio를 사용하여 실행 가능한 jar 만들기Android Studio를 사용하여 실행 가능한 항아리를 만드는 방법을 설명합니다. OS 버전은 다음과 같습니다. Android Studio 버전은 다음과 같습니다. 자바 버전은 다음과 같습니다. 다음 절차에 따라...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.