Java 如何配置Maven2发布到Artifactory?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24122382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Maven2 to publish to Artifactory?
提问by IAmYourFaja
Currently I have a Maven2 project that builds a JAR when you run:
目前我有一个 Maven2 项目,当你运行时它会构建一个 JAR:
mvn clean package
I need to now tweak the pom.xmlto publish this JAR (myapp.jar) to an Artifactory server running at:
我现在需要调整pom.xml以将此 JAR ( myapp.jar)发布到运行于以下位置的 Artifactory 服务器:
http://myartifactory/artifactory/simple/myorg/myapp/0.1
I tried adding a <repositories>element to my pom.xmlbut nothing is being published with this config:
我尝试向我添加一个<repositories>元素,pom.xml但没有使用此配置发布任何内容:
<repositories>
<repository>
<id>myartifactory</id>
<url>http://myartifactory/artifactory/simple/</url>
</repository>
</repositories>
Any ideas as to how I could get publishing to work? For simplicity's sake, pretend that this Artifactory repo is authenticated to accept publishes/writes from a user with a username=fooand password=bar.
关于如何让发布工作的任何想法?为简单起见,假设此 Artifactory 存储库经过身份验证以接受来自具有username=foo和的用户的发布/写入password=bar。
采纳答案by JBaruch
You have two options (please note that the later is the recommended one):
您有两种选择(请注意,推荐的是后者):
Add DistributionManagementpart to your pom and serverpart to your settings.xml
将DistributionManagement一部分添加到您的 pom 并将server一部分添加到您的settings.xml
- Let's say you want to deploy to libs-snapshot-local repository. In this case you need to go to the tree browser in Artifactory, focus on the repository level, copy the
Distribution Managementsnippet and paste it in yourpom.xml:
- Next, you need to tell maven the credentials. For that, click on your username in the top right corner, enter your password to unlock the screen, copy the
servertag fromMaven Settingspanel:
This one you paste in your settings.xml. Don't forget to replace the ${server-id} with the real server id (the one you have in Distribution Management now). - Now, just run
mvn deployand enjoy.
- 假设您要部署到 libs-snapshot-local 存储库。在这种情况下,您需要转到 Artifactory 中的树浏览器,专注于存储库级别,复制
Distribution Management代码段并将其粘贴到您的pom.xml:
- 接下来,您需要告诉 Maven 凭据。为此,请单击右上角的用户名,输入密码以解锁屏幕,
server从Maven Settings面板复制标签:
您粘贴到settings.xml. 不要忘记将 ${server-id} 替换为真实的服务器 ID(您现在在 Distribution Management 中拥有的那个)。 - 现在,只需运行
mvn deploy并享受。
Working with Maven Artifactory Plugin:
使用 Maven Artifactory 插件:
- Add the relevant
<plugin>part as described in the wikito yourpom.xml. It includes both the target repository and the credentials (please use external credentials source, like environment variables or system properties). - Run
mvn deployand enjoy not only the deployment to Artifactory, but also additional features as described below.
<plugin>将wiki 中描述的相关部分添加到您的pom.xml. 它包括目标存储库和凭据(请使用外部凭据源,如环境变量或系统属性)。mvn deploy不仅可以运行并享受到 Artifactory 的部署,还可以享受如下所述的附加功能。
Additional features of Artifactory Maven Plugin (on top of regular Maven deployment):
Artifactory Maven 插件的附加功能(在常规 Maven 部署之上):
- Allow adding custom propertiesto the deployed files
- Provide the build bill of materials (the buildInfo), allowing Build Integrationwith any build server (even those not supported by JFrog) or even with standalone builds (without build server at all).

