Java:发布Maven项目到Github私有仓库

准备好Maven项目下的类

package com.mouday;

public class Hello {
    public void sayHello(){
        System.out.println("Hello");
    }
}

1、创建两个GITHUB_TOKEN

一个用于发布,一个用于使用

https://github.com/settings/tokens

用户设置 Settings 
-> Developer settings 
-> Personal access tokens
-> New personal access token

2、设置账号密码

~/.m2/settings.xml

<servers>
     <server>
        <id>githubid>
        <username>moudayusername>
        <password>GITHUB_TOKENpassword>
    server>
servers>

3、设置仓库地址

pom.xml

<distributionManagement>
    <repository>
        <id>githubid>
        <name>GitHub OWNER Apache Maven Packagesname>
        <url>https://maven.pkg.github.com/mouday/hello-packageurl>
    repository>
distributionManagement>

4、发布到Github私有仓库

mvn clean package deploy

查看
https://github.com/mouday/hello-package/packages/

Java:发布Maven项目到Github私有仓库_第1张图片

5、下载使用

pom.xml

<project>
    <repositories>
        
        <repository>
            <id>githubid>
            <name>GitHub OWNER Apache Maven Packagesname>
            <url>https://maven.pkg.github.com/mouday/hello-packageurl>
        repository>
    repositories>

    <dependencies>
        
        <dependency>
            <groupId>com.moudaygroupId>
            <artifactId>hello-packageartifactId>
            <version>1.0version>
        dependency>
    dependencies>
project>

引入Hello类使用

package com.mouday;

public class demo {
    public static void main(String[] args) {
        Hello hello = new Hello();
        hello.sayHello();
    }
}

参考
https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages

你可能感兴趣的:(Java:发布Maven项目到Github私有仓库)