[英]Using github repository as maven dependency
我創建了一個項目,其中包含一些可重用的方法,這些方法可以通過將其添加為依賴項來用於其他項目。 為此,我在 pom.xml 文件中添加了以下內容,當我運行mvn clean deploy
branch 時,使用工件成功創建了分支。
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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
<name>API Authenticator</name>
<description>Project to authenticate API usage</description>
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Staging Repository</name>
<url>file://${project.build.directory}/${version}</url>
</repository>
</distributionManagement>
<properties>
<github.global.server>github</github.global.server>
<java.version>11</java.version>
<java-jwt.version>3.16.0</java-jwt.version>
<jwks-rsa.version>0.18.0</jwks-rsa.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${java-jwt.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>jwks-rsa</artifactId>
<version>${jwks-rsa.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${project.build.directory}</outputDirectory>
<branch>refs/heads/${version}</branch>
<includes>
<include>**/*</include>
</includes>
<merge>true</merge>
<repositoryName>rwg-dip-api-authenticator</repositoryName>
<repositoryOwner>robert-walters</repositoryOwner>
<server>github</server>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>
internal.repo::default::file://${project.build.directory}/${version}
</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
</project>
在 settings.xml(Maven 主頁:/opt/homebrew/Cellar/maven/3.8.2/libexec)中,我生成了具有所需所有訪問權限的個人訪問令牌並添加了它。
<server>
<id>github</id>
<password>access_token</password>
</server>
為了將其用作依賴項,我在項目中添加了以下內容,我想在其中重用函數,當我從 IntelliJ 重新導入依賴項時,我可以在外部依賴項中看到內部項目的依賴項但是當我運行項目時,它顯示java: package com.abc.util 雖然不存在但我在 Intellj 中得到了 class 的建議。
<repositories>
<repository>
<id>https://github.com/me/api-authenticator</id>
<url>https://github.com/me/api-authenticator/1.0.0</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
</dependency>
我已經完成了以下內容,但對上述情況沒有幫助
https://www.baeldung.com/maven-repo-github
https://dev.to/iamthecarisma/hosting-a-maven-repository-on-github-site-maven-plugin-9ch
更新
正如 M.Deinum 所建議的那樣,我已經刪除了spring-boot-maven-plugin
,現在我可以將它用作 Intellj 中其他項目的依賴項,並且它在本地工作正常但是當管道執行為項目創建構建時mvn package
步驟失敗並顯示“缺少 com.abc:api-authenticator:jar:1.0.0 的 POM,沒有可用的依賴信息”
如果您願意為此使用外部服務,您可以查看https://jitpack.io/ 。
它能夠直接從 GitHub 存儲庫構建您的 maven 項目,然后充當為工件提供服務的 maven 存儲庫。
第一次下載工件需要時間(因為它僅在第一次請求工件時構建項目),但隨后它會為下一個請求重用已構建的工件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.