[英]How to download the latest jar file from GitHub packages and deploy to cloud hub using Maven GitHub actions?
[英]How to deploy an artifact (Maven) to Github package using github actions
我正在嘗試使用 Maven 作為構建工具為一個簡單的 Spring Boot 應用程序編寫 github 操作管道。 構建和驗證成功,但將 Jar 部署到 Github Registry 失敗並顯示錯誤:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project space-management-system: Failed to deploy artifacts/metadata: Cannot access registry=https://maven.pkg.github.com/Pranav3105/osmosis with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access registry=https://maven.pkg.github.com/Pranav3105/osmosis using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
[ERROR] role: org.apache.maven.wagon.Wagon
[ERROR] roleHint: registry=https
這是我的 pom.xml
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<groupId>com.mindtree</groupId>
<artifactId>space-management-system</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>space-management-system</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<dependencies>
.........
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
<profiles>
<profile>
<id>sonar</id>
<properties>
...sonar properties.....
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<repository>
<id>github</id>
<name>pranav3105</name>
<url>registry=https://maven.pkg.github.com/Pranav3105/osmosis</url>
</repository>
</distributionManagement>
</project>
這是我創建的工作流文件:
name: Master Branch
on:
push:
branches:
- 'master'
jobs:
test:
name: Test - Units & Integrations
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11.0.4
- name: Maven Package
run: mvn -B clean package -DskipTests
- name: Maven Verify
run: mvn -B clean verify -DskipTests
sonar:
name: Test - SonarCloud Scan
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11.0.4
- name: SonarCloud Scan
run: mvn -B clean verify -DskipTests -Psonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
artifact:
name: Publish - GitHub Packages
runs-on: ubuntu-18.04
needs: [test, sonar]
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11.0.4
- name: Publish artifact on GitHub Packages
run: mvn -B -e -X clean deploy -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
我還嘗試將服務器標記放在 settings.xml 中,在 maven 部署階段將其作為參數傳遞,但也因相同的錯誤而失敗。
我認為您應該從 pom.xml 中的 distributionManagement > repository > url 的開頭刪除“registry=”
<distributionManagement>
<repository>
<id>github</id>
<name>pranav3105</name>
<url>https://maven.pkg.github.com/Pranav3105/osmosis</url>
</repository>
</distributionManagement>
看看這個 repo ,這是一個很好的樣本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.