github maven_在Github上托管Maven存储库:site-maven-plugin

github maven

本文提供了使用site-maven-plugin从GitHub发布maven项目的逐步指南。

先决条件

  • Github上的项目存储库
  • Java和Maven
  • 熟悉Maven配置

如果您还没有一个Maven项目,请在Github上创建一个存储库,然后推送您的Maven项目。 该方法将使用site-maven-plugin将工件推送到Github。

该方法不会将gh-pages和其他分支冲突,因为将工件推送到存储库的mvn-repo分支时,每次执行mvn deploy命令时,都会发布新的构建工件。

首先,必须将Maven工件部署到build / target目录中的临时位置。 将以下存储库添加到项目pom.xml中:

<distributionManagement>
    <repository>
        <id> internal.repo </id>
        <name> Temporary Staging Repository </name>
        <url> file://${project.build.directory}/mvn-repo </url>
    </repository>
</distributionManagement>

将maven-deploy-plugin配置添加到pom.xml:

<plugin>
    <artifactId> maven-deploy-plugin </artifactId>
    <version> 2.8.2 </version>
    <configuration>
        <altDeploymentRepository> internal.repo::default::file://${project.build.directory}/mvn-repo </altDeploymentRepository>
    </configuration>
</plugin> 

将上述存储库和插件添加到pom.xml后,执行mvn deploy ,将把maven存储库部署到目录target/mvn-repo/ 。 下一步是部署到github mvn-repo分支。

~/.m2/settings.xml配置github身份验证信息,以启用将site-maven-plugin推送到github。 如果文件settings.xml不存在,则应创建它。

有几种方法可以验证github,将以下配置之一添加到~/.m2/settings.xml

使用您的github用户名和密码:

<settings>
  <servers>
    <server>
      <id> github </id>
      <username> GitHubLogin </username>
      <password> GitHubPassw0rd </password>
    </server>
  </servers>
</settings>

使用OAUTH2TOKEN

<settings>
  <servers>
    <server>
      <id> github </id>
      <password> OAUTH2TOKEN </password>
    </server>
  </servers>
</settings>

然后将以下内容添加到pom.xml中

<properties>
  <github.global.server> github </github.global.server>
</properties>

最后一步是配置site-maven-plugin以将您的本地分段repo target/mvn-repo/推送到远程mvn-repo分支。

<plugin>
    <groupId> com.github.github </groupId>
    <artifactId> site-maven-plugin </artifactId>
    <version> 0.11 </version>
    <configuration>
        <message> Maven artifacts for ${project.version} </message> <!-- git commit message -->
        <noJekyll> true </noJekyll>  <!-- disable webpage processing -->
        <outputDirectory> ${project.build.directory}/mvn-repo </outputDirectory> <!-- matches distribution management repository url above -->
        <branch> refs/heads/mvn-repo </branch> <!-- remote branch name -->
        <includes><include> **/* </include></includes>
        <repositoryName> YOUR-REPOSITORY-NAME </repositoryName> <!-- github repo name -->
        <repositoryOwner> THE-REPOSITORY-OWNER </repositoryOwner> <!-- organization or user name  -->
    </configuration>
    <executions> <!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase -->
      <execution>
        <goals>
          <goal> site </goal>
        </goals>
        <phase> deploy </phase>
      </execution>
    </executions>
</plugin>

repositoryOwner值是回购的父名称,如果回购由github组织拥有,则该值将是组织名称,如果回购由用户拥有,则该值将是用户名,例如回购keyvaluedb / key- value-db-java ,repositoryName的值为key-value-db-java ,repositoryOwner的值为keyvaluedb

执行mvn deploy将您的工件上传到github。 如果mvn-repo分支不存在,则将创建它。

在浏览器中访问github.com,选择mvn-repo分支,并验证是否已上传所有二进制文件。

替代文字

万岁 。 您的maven项目现在可以在其他项目中使用。

每次在项目上运行mvn clean deploy命令时,最新的工件都将上传到github。

可以将使用您的项目的其他Maven项目配置为从github提取您的工件。 将以下代码段添加到依赖于您的项目的pom.xml文件中。

<dependency>
    <groupId> YOUR.PROJECT.GROUPID </groupId>
    <artifactId> ARTIFACT-ID </artifactId>
    <version> VERSION </version>
</dependency>
<repository>
    <id> ARTIFACT-ID </id>
    <url> https://raw.github.com/REPOSITORYOWNER/REPOSITORY-NAME/mvn-repo/ </url>
</repository>

将属性添加到pom.xml后,该项目将自动从github下载您的maven存储库jar。

翻译自: https://dev.to/iamthecarisma/hosting-a-maven-repository-on-github-site-maven-plugin-9ch

github maven

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值