文章目录
提示:以下是本篇文章正文内容,下面案例可供参考
一、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中方法:
调用:
成功: