本文翻译自: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: 我能找到的最佳解决方案包括以下步骤:
- Create a branch called
mvn-repo
to host your maven artifacts. 创建一个名为mvn-repo
的分支来托管你的maven工件。 - Use the github site-maven-plugin to push your artifacts to github. 使用github site-maven-plugin将你的工件推送到github。
- 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 calledgh-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