将 Maven 项目发布到 Github 包
Publish Maven project to Github Package
Objective
将私有 Maven 项目发布到 GitHub 包作为私有仓库供其他项目使用。
获取错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project SecuritySpringBootContracts: Failed to deploy artifacts: Could not transfer artifact com.sagar:SecuritySpringBootContracts:jar:0.0.3 from/to contracts (https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts): transfer failed for https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts/com/sagar/SecuritySpringBootContracts/0.0.3/SecuritySpringBootContracts-0.0.3.jar, status: 422 Unprocessable Entity
我在 GitHub
的私人仓库
https://github.com/sagarnayak/SecuritySpringBootContracts
我的代码
Settings.xml 在 C:\Users\SAGAR\.m2
<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">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>contracts</id>
<url>https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>contracts</id>
<username>sagarnayak</username>
<password>ghp_WRGrhj380s8vikAcZMp4j1z02</password>
</server>
</servers>
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 https://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.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sagar</groupId>
<artifactId>SecuritySpringBootContracts</artifactId>
<version>0.0.3</version>
<name>SecuritySpringBootContracts</name>
<description>SecuritySpringBootContracts</description>
<properties>
<java.version>11</java.version>
<kotlin.version>1.5.31</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>contracts</id>
<name>contracts package</name>
<url>https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts</url>
</repository>
</distributionManagement>
</project>
当我键入 mvnw deploy 时,出现错误 -
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project SecuritySpringBootContracts: Failed to deploy artifacts: Could not transfer artifact com.sagar:SecuritySpringBootContracts:jar:0.0.3 from/to contracts (https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts): transfer failed for https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts/com/sagar/SecuritySpringBootContracts/0.0.3/SecuritySpringBootContracts-0.0.3.jar, status: 422 Unprocessable Entity
如有任何建议,我们将不胜感激。
如本期所述
原因似乎是您的 Maven 工件的名称,它必须是小写的。
在您的 pom.xml
中,例如使用 <artifactId>security-springboot-contracts</artifactId>
而不是 <artifactId>SecuritySpringBootContracts</artifactId>
应用程序启动时创建的快照版本错误,应该类似于0.0.1-SNAPSHOT
例如:0.0.1-SNAPSHOT 或 0.0.3-SNAPSHOT
在你的例子中,它是用 0.0.3 创建的
Objective
将私有 Maven 项目发布到 GitHub 包作为私有仓库供其他项目使用。
获取错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project SecuritySpringBootContracts: Failed to deploy artifacts: Could not transfer artifact com.sagar:SecuritySpringBootContracts:jar:0.0.3 from/to contracts (https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts): transfer failed for https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts/com/sagar/SecuritySpringBootContracts/0.0.3/SecuritySpringBootContracts-0.0.3.jar, status: 422 Unprocessable Entity
我在 GitHub
的私人仓库https://github.com/sagarnayak/SecuritySpringBootContracts
我的代码
Settings.xml 在 C:\Users\SAGAR\.m2
<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">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>contracts</id>
<url>https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>contracts</id>
<username>sagarnayak</username>
<password>ghp_WRGrhj380s8vikAcZMp4j1z02</password>
</server>
</servers>
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 https://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.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sagar</groupId>
<artifactId>SecuritySpringBootContracts</artifactId>
<version>0.0.3</version>
<name>SecuritySpringBootContracts</name>
<description>SecuritySpringBootContracts</description>
<properties>
<java.version>11</java.version>
<kotlin.version>1.5.31</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>contracts</id>
<name>contracts package</name>
<url>https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts</url>
</repository>
</distributionManagement>
</project>
当我键入 mvnw deploy 时,出现错误 -
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project SecuritySpringBootContracts: Failed to deploy artifacts: Could not transfer artifact com.sagar:SecuritySpringBootContracts:jar:0.0.3 from/to contracts (https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts): transfer failed for https://maven.pkg.github.com/sagarnayak/SecuritySpringBootContracts/com/sagar/SecuritySpringBootContracts/0.0.3/SecuritySpringBootContracts-0.0.3.jar, status: 422 Unprocessable Entity
如有任何建议,我们将不胜感激。
如本期所述
原因似乎是您的 Maven 工件的名称,它必须是小写的。
在您的 pom.xml
中,例如使用 <artifactId>security-springboot-contracts</artifactId>
而不是 <artifactId>SecuritySpringBootContracts</artifactId>
应用程序启动时创建的快照版本错误,应该类似于0.0.1-SNAPSHOT
例如:0.0.1-SNAPSHOT 或 0.0.3-SNAPSHOT
在你的例子中,它是用 0.0.3 创建的