在github上托管Maven存储库

本文翻译自:Hosting a Maven repository on github

I have a fork of a small open sourced library that I'm working on on github. 我有一个小型开源库的分支,我正在github上工作。 I'd like to make it available to other developers via maven, but I don't want to run my own Nexus server, and because it's a fork I can't easily deploy it to oss.sonatype.org. 我想通过maven将其提供给其他开发人员,但我不想运行自己的Nexus服务器,因为它是一个分支,我不能轻易地将它部署到oss.sonatype.org。

What I'd like to do is to deploy it to github so that others can access it using maven. 我想要做的是将它部署到github,以便其他人可以使用maven访问它。 What's the best way to do this? 最好的方法是什么?


#1楼

参考:https://stackoom.com/question/wnaW/在github上托管Maven存储库


#2楼

The best solution I've been able to find consists of these steps: 我能找到的最佳解决方案包括以下步骤:

  1. Create a branch called mvn-repo to host your maven artifacts. 创建一个名为mvn-repo的分支来托管你的maven工件。
  2. Use the github site-maven-plugin to push your artifacts to github. 使用github site-maven-plugin将你的工件推送到github。
  3. Configure maven to use your remote mvn-repo as a maven repository. 配置maven以将远程mvn-repo用作maven存储库。

There are several benefits to using this approach: 使用此方法有几个好处:

  • Maven artifacts are kept separate from your source in a separate branch called mvn-repo , much like github pages are kept in a separate branch called gh-pages (if you use github pages) Maven工件在一个名为mvn-repo的独立分支中与源保持独立,就像github页面保存在一个名为gh-pages的单独分支中一样(如果你使用github页面)
  • Unlike some other proposed solutions, it doesn't conflict with your gh-pages if you're using them. 与其他一些提议的解决方案不同,如果您使用它们,它不会与您的gh-pages冲突。
  • Ties in naturally with the deploy target so there are no new maven commands to learn. 与部署目标自然匹配,因此没有新的maven命令可供学习。 Just use mvn deploy as you normally would 像往常一样使用mvn deploy

The typical way you deploy artifacts to a remote maven repo is to use mvn deploy , so let's patch into that mechanism for this solution. 将工件部署到远程maven repo的典型方法是使用mvn deploy ,所以让我们修补此解决方案的机制。

First, tell maven to deploy artifacts to a temporary staging location inside your target directory. 首先,告诉maven将工件部署到目标目录中的临时临时位置。 Add this to your pom.xml : 将其添加到您的pom.xml

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

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

Now try running mvn clean deploy . 现在尝试运行mvn clean deploy You'll see that it deployed your maven repository to target/mvn-repo . 您将看到它将您的maven存储库部署到target/mvn-repo The next step is to get it to upload that directory to GitHub. 下一步是让它将该目录上传到GitHub。

Add your authentication information to ~/.m2/settings.xml so that the github site-maven-plugin can push to GitHub: 将您的身份验证信息添加到~/.m2/settings.xml以便github site-maven-plugin可以推送到GitHub:

<!-- NOTE: MAKE SURE THAT settings.xm
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值