github创建自己的maven远程仓库和使用过程记录

4 篇文章 0 订阅
3 篇文章 0 订阅


提示:以下是本篇文章正文内容,下面案例可供参考

一、github创建仓库

在这里插入图片描述
注意这边的用户名称待会是需要的,可以在右上角->settings->Account修改
在这里插入图片描述

二、部署本地项目到远程仓库<三步骤>

2.1 配置本地maven仓库信息*

在这里插入图片描述

    <server>
         <!--github-->  
         <id>github</id>
         <!--github账号-->  
         <username>xxxx</username>
         <!--github密码-->  
         <password>xxxx</password>
      </server>

2.2 配置项目pom信息

在这里插入图片描述

 <build>
        <plugins>
            <!-- deploy创建本地仓库,在target目录下 -->
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.1</version>
                <configuration>
                    <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/test-maven</altDeploymentRepository>
                </configuration>
            </plugin>
            <!-- 配置推送到远程仓库 -->
            <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}/test-maven</outputDirectory>
                    <!--分支的名称 注意refs/heads/必须添加-->
                    <branch>refs/heads/main</branch>
                    <merge>true</merge>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <!--对应github上创建的仓库名称 name-->
                    <repositoryName>test-maven</repositoryName>
                    <!--github 仓库所有者即登录用户名-->
                    <repositoryOwner>jonycw</repositoryOwner>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

2.3 打包推送部署

命令:mvn clean deploy

在这里插入图片描述

2.4 成功显示(github)

在这里插入图片描述
参考文章:https://malalanayake.wordpress.com/2014/03/10/create-simple-maven-repository-on-github/

三、错误未知问题

3.1、Failed to execute goal com.github.github:site-maven-plugin:0.12:site (default) on project testJenkins: Error creating blob: cannot retry due to server authentication, in streaming mode

授权失败,更改账号密码验证改为token验证解决问题 如 `5.1 更改验证方式 token 验证github`

3.2、版本兼容错误

在这里插入图片描述
可参考论坛:https://github.com/github/maven-plugins/issues/36 未解决

四、采用其它方式

4.1 更改验证方式 token 验证github

4.1.1 github生成token
settings->Developer settings->personal access tokens->generate new token

暂时全部选择,具体需求可根据情况选择:

在这里插入图片描述

生成后保存当前token
4.1.2 settings.xml对应配置修改为:

在这里插入图片描述

4.1.3 pom中配置修改为:
<build>
    <plugins>
        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
            <configuration>
                <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/test-maven</altDeploymentRepository>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.github.github</groupId>
            <artifactId>site-maven-plugin</artifactId>
            <version>0.12</version>
            <configuration>
                <message>Creating site for ${project.artifactId} ${project.version}</message>
                <noJekyll>true</noJekyll>
                <!--本地jar地址, 对应上面的altDeploymentRepository-->
                <outputDirectory>${project.build.directory}/test-maven</outputDirectory>
                <!--分支-->
                <branch>refs/heads/main</branch>
                <merge>true</merge>
                <includes>
                    <include>**/*</include>
                </includes>
                <!--对应github上创建的仓库名称 name-->
                <repositoryName>test-maven</repositoryName>
                <!--github登录账号 对应的密码存在maven的setting.xml文件中-->
                <!--由github组织拥有,则该值将是组织名称,如果由用户拥有,则该值将是用户名-->
                <repositoryOwner>jonycw</repositoryOwner>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>site</goal>
                    </goals>
                    <phase>deploy</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<properties>
    <github.global.server>github</github.global.server>
</properties>

重新运行:

mvn clean deploy   `成功如下`

在这里插入图片描述

五、引用

<repositories>
    <repository>
        <id>mvn-repo</id>
        <!-- https://raw.github.com/用户名/仓库名/分支名 -->
        <url>https://raw.github.com/jonycw/test-maven/main</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

在这里插入图片描述

5.1 调用案例

打包的jar中方法:

在这里插入图片描述
调用:
在这里插入图片描述
成功:
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值