Overview
As a Maven repository, Artifactory is both a source for artifacts needed for a build, and a target to deploy artifacts generated in the build process. Maven is configured using a settings.xml file located under your Maven home directory (typically, this will be /user.home/.m2/settings.xml). For more information on configuring Maven please refer to the Apache Maven Project Settings Reference.
作为Maven存储库,Artifactory既是构建所需的artifacts(组件)的来源,也是部署过程中生成的需要发布的artifacts的目的地(可理解为既可从仓库获取组件,也可发布组件到仓库)。Maven的配置文件settings.xml位于Maven主目录下(通常情况下在/user.home/.m2/settings.xml ). 有关配置Maven的更多信息,请参阅Apache Maven项目设置参考 .
The default values in this file configure Maven to work with a default set of repositories used to resolve artifacts and a default set of plugins.
此文件(settings.xml)中的默认值配置Maven的默认仓库,通过这些仓库使用组件、插件。
To work with Artifactory you need to configure Maven to perform the following two steps:
Resolving Artifacts Through Artifactory
Deploying Artifacts Through Artifactory
要正确使用Artifactory,需要配置Maven,以实现下面两个步骤:
1、通过Artifactory 解析组件(获取组件)
2、通过Artifactory 发布组件(发布组件)
Once your Maven build is configured, Artifactory also provides tight integration with commonly used CI servers (such as Jenkins, TeamCity or a Bamboo) through a set of plugins that you can freely install and use.
一旦配置了Maven构建,Artifactory通过插件(可以自由安装和使用的)提供与一些常用CI服务器的紧密集成(such as Jenkins, TeamCity or a Bamboo)。
Viewing Maven Artifacts
Selecting a Maven metadata file (maven-metadata.xml) or a POM file (pom.xml) from the Tree browsing mode in the Artifact Repository Browser, provides you with details on the selected item.
从库浏览器中的树浏览模式选择一个Maven元数据文件(maven-metadata.xml) 或 POM 文件 (pom.xml),可提供所选项目的详细信息。
Maven Metadata View
POM View
Resolving Artifacts Through Artifactory
To configure Maven to resolve artifacts through Artifactory you need to modify the settings.xml. You can generate one automatically, or modify it manually.
如果通过Artifactory解析组件,需要修改maven的配置文件settings.xml。Artifactory可以自动生产settings.xml,也可以手动修改。
Automatically Generating Settings
To make it easy for you to configure Maven to work with Artifactory, Artifactory can automatically generate a settings.xml file which you can save under your Maven home directory.
为了便于您配置Maven以适用于Artifactory,Artifactory可以自动生成settings.xml文件,可以保存在您的Maven主目录下。
The definitions in the generated settings.xml file override the default central and snapshot repositories of Maven.
Artifactory生成的settings.xml,重写maven的默认central 和snapshot仓库。
Once you have created your Maven repository, go to Application | Artifactory | Artifacts, select your Maven repository and click Set Me Up.
一旦创建了Maven仓库,就可以点击 Application | Artifactory | Artifacts ,然后选择该Maven仓库并单击Set Me Up。
In the Set Me Up dialog, click Generate Maven Settings.
在Set Me Up中,单击Generate Maven Settings. .
You can now specify the repositories you want to configure for Maven.
现在,你可以选择想要为maven配置的仓库。
Once you have configured the settings for Maven, click Generate Settings to generate and save the settings.xml file.
配置好maven的设置选项,点击Generate Settings,生产并保存settings.xml文件。
Provisioning Dynamic Settings for Users
You can deploy and provision a dynamic settings template for your users.
您可以为用户部署和设置动态设置模板。
Once downloaded, settings are generated according to your own logic and can automatically include user authentication information.
一旦下载,根据您自己的逻辑,自动地包括用户认证信息,生成设置。
For more details, please refer to the Provisioning Build Tool Settings under Filtered Resources.
有关详细信息,请参阅Provisioning Build Tool Settings under Filtered Resources。
Manually Overriding the Built-in Repositories
To override the built-in central and snapshot repositories of Maven, you need to ensure that Artifactory is correctly configured so that no request is ever sent directly to them.
为了覆盖maven的内置central 和 snapshot仓库,您需要确保Artifactory被正确配置,这样就不会直接向它们发送任何请求。
Using the automatically generated file as a template
使用自动生成的文件作为模板。
You can use the automatically generated settings.xml file as an example when defining the repositories to use for resolving artifacts.
在定义用于解析组件的仓库时,可以使用自动生成的settings.xml为例。
To do so, you need to insert the following into your parent POM or settings.xml (under an active profile):
为此,需要在父POM或者settings.xml(under an active profile)中插入以下内容:
<repositories>
<repository>
<id>central</id>
<url>http://[host]:[port]/artifactory/libs-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://[host]:[port]/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://[host]:[port]/artifactory/plugins-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://[host]:[port]/artifactory/plugins-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
Using the Default Global Repository
使用默认全局仓库
You can configure Maven to run with the Default Global Repository so that any request for an artifact will go through Artifactory which will search through all of the local and remote repositories defined in the system.
可以将Maven配置为使用默认全局仓库运行,以便对组件的任何请求都将通过Artifactory,Artifactory将搜索系统中定义的所有本地和远程仓库。
We recommend that you fine tune Artifactory to search through a more specific set of repositories by defining a dedicated virtual (or local) repository, and configure Maven to use that to resolve artifacts instead.
我们建议您通过定义一个专用的虚拟(或本地)仓库来微调(fine tune)Artifactory,以便在一组更具体(可理解为更加适合当前maven工程)的仓库中进行搜索,并将Maven配置为使用它来解析组件。
Additional Mirror Any Setup
In addition to overriding built-in Maven repositories, you can use the Mirror Any setting to redirect all requests to a Maven repository through Artifactory, including those defined inside POMs of plug-ins and third party dependencies. (While it does not adhere to best practices, it is not uncommon for POMs to reference Maven repositories directly). This ensures no unexpected requests directly to Maven are introduced by such POMs.
除了覆盖内置Maven仓库之外,您还可以使用Mirror Anysetting,通过Artifactory将所有请求重定向到Maven仓库,包括在插件pom和第三方依赖项中定义的请求(虽然它不遵循最佳实践,但是POMs直接引用Maven存储库并不少见)。这确保了此类pom不会直接向Maven引入意外请求。
You can either check Mirror Any in the Maven Settings screen when generating your settings.xml file, or you can manually insert the following:
生成Settings.xml文件时,可以在Maven Settings屏幕中选中Mirror Any,也可以手动插入以下内容:
<mirrors>
<mirror>
<id>artifactory</id>
<mirrorOf>*</mirrorOf>
<url>http://[host]:[port]/artifactory/[virtual repository]</url>
<name>Artifactory</name>
</mirror>
</mirrors>
注意:
Care when using “Mirror Any”
使用“Mirror Any”要注意
While this is a convenient way to ensure Maven only accesses repositories through Artifactory, it defines a coarse proxying rule that does not differentiate between releases and snapshots and relies on the single specified repository to do this resolution.
虽然这是确保Maven只通过Artifactory访问仓库的一种方便方法,但它定义了一个粗略的代理规则,该规则不区分releases和snapshots,并且依赖于单个指定的仓库来执行此解决方案。
For more information on using mirrors please refer to Using Mirrors for Repositories in the Apache Maven documentation.
有关使用镜像的更多信息,请参阅ApacheMaven文档中的using mirrors For Repositories。
Configuring Authentication
Artifactory requires user authentication in three cases:
Artifactory在三种情况下需要用户身份验证:
1、 Anonymous access has been disabled by unchecking the global Allow Anonymous Access setting.
2、 You want to restrict access to repositories to a limited set of users
3、 When deploying builds (while theoretically possible, it is uncommon to allow anonymous access to deployment repositories)
1、 通过取消选中“全局允许匿名访问”设置,已禁用匿名访问。
2、 您希望将对存储库的访问限制为一组限定用户
3、 部署构建时(虽然理论上是可能的,但允许匿名访问部署存储库是不常见的)
Authentication is configured in Maven using elements in the settings.xml file.
在Maven中使用settings.xml文件中的元素配置身份验证。
Each and element specified in the file must have a corresponding element with a matching that specifies the username and password.
文件中指定的每个和元素都必须有一个对应的元素,该元素具有指定用户名和密码的匹配。
The sample snippet below emphasizes that the element with id=central has a corresponding element with id=central.
下面的示例片段强调id=central的元素有一个id=central的对应元素。
Similarly, the element with id=snapshots has a corresponding element with id=snapshots.
类似地,id=snapshots的元素有一个id=snapshots的对应元素。
The same would hold for elements that require authentication.
对于需要身份验证的元素也是如此。
In both cases the username is admin and the password is encrypted.
在这两种情况下,用户名是admin,密码是加密的。
<servers>
<server>
<id>central</id>
<username>admin</username>
<password>\{DESede\}kFposSPUydYZf89Sy/o4wA==</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>\{DESede\}kFposSPUydYZf89Sy/o4wA==</password>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<id>central</id>
<snapshots>
<enabled>false</enabled>
</snapshots>
<name>libs-release</name>
<url>http://localhost:8081/artifactory/libs-release</url>
</repository>
<repository>
<id>snapshots</id>
<snapshots />
<name>libs-snapshot</name>
<url>http://localhost:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
</profile>
</profiles>
注意:
Artifactory encrypts passwords for safe and secure access to Maven repositories
Artifactory加密密码以安全访问Maven存储库
To avoid having to use cleartext passwords, Artifactory encrypts the password in the settings.xml file that is generated. For example, in the above sample snippet we can see that the admin user name is specified in cleartext, but the password is encrypted:
为了避免使用明文密码,Artifactory对生成的settings.xml文件中的密码进行加密。例如,在上面的示例代码片段中,我们可以看到管理员用户名是在明文中指定的,但是密码是加密的。
Synchronizing authentication details for repositories with the same URL
同步具有相同URL的存储库的身份验证详细信息
If you have repository definitions (either for deployment or download) that use the same URL, Maven takes the authentication details (from the corresponding server definition) of the first repository encountered and uses it for the life-time of the running build for all repositories with the same URL.
如果您有使用相同URL的存储库定义(用于部署或下载),Maven将获取遇到的第一个存储库的身份验证详细信息(来自相应的服务器定义),并将其用于具有相同URL的所有存储库的运行生成的生命周期。
This may cause authentication to fail (producing 401 errors for downloads or deployment) if you are using different authentication details for the respective repositories. This is inherent Maven behavior and can only be solved by using the same authentication details for all repository definitions with the same URL in your settings.xml.
如果对相应存储库使用不同的身份验证详细信息,这可能会导致身份验证失败(为下载或部署生成401个错误)。这是Maven固有的行为,只能通过对settings.xml中具有相同URL的所有存储库定义使用相同的身份验证详细信息来解决。
Forcing Authentication on Virtual Maven Repositories
强制对虚拟Maven存储库进行身份验证
Artifactory supports Maven repositories with Allow Anonymous Access enabled by default and will not query the Maven client for authentication parameters.
If you want to enforce authentication you need to explicitly instruct Artifactory to request authentication parameters.
Artifactory支持Maven存储库,默认情况下启用了Allow Anonymous Access,并且不会向Maven客户机查询身份验证参数。如果要强制身份验证,则需要显式指示Artifactory请求身份验证参数。
In the New or Edit Repository dialog of the Maven virtual repositories, select the Force Authentication check box.
在Maven虚拟存储库的New或Edit Repository对话框中,选中Force Authentication复选框。
当选择Force Authentication时,Artifactory将在尝试访问此存储库之前从Maven客户端请求身份验证参数。
Deploying Artifacts Through Artifactory
Setting Up Distribution Management
设置分布式管理
To deploy build artifacts through Artifactory you must add a deployment element with the URL of a target local repository to which you want to deploy your artifacts.
要通过Artifactory部署构建组件,必须添加一个部署元素,其中包含要将组件部署到的目标本地存储库的URL。
To make this easier, Artifactory displays a code snippet that you can use as your deployment element. In the Artifact Repository Browser, click Tree and select the repository you want to deploy to and click Set Me Up. The code snippet is displayed under Deploy.
为了更简单,Artifactory显示了一个代码片段,您可以将其用作部署元素。在Artifact Repository浏览器中,单击树并选择要部署到的存储库,然后单击Set Me Up。代码段显示在“Deploy”下。
Remember that you can not deploy build artifacts to remote, so you should not use them in a deployment element.
请记住,您不能将构建组件部署到远程,因此不应在部署元素中使用它们。
Setting Up Security in Maven Settings
在Maven设置中设置安全性
When deploying your Maven builds through Artifactory, you must ensure that any element in your distribution settings has a corresponding element in the settings.xml file with a valid username and password as described in Configuring Authentication above. For the example displayed above, the Maven client expects to find a element in the settings.xml with artifactory specified.
在通过Artifactory部署Maven时,必须确保分发设置中的任何元素在settings.xml文件中都有相应的元素,该元素具有有效的用户名和密码,如上面Configuring Authentication中所述。对于上面显示的示例,Maven客户机希望在settings.xml中找到指定了artifactory的元素。
注意:
Anonymous access to distribution repository
匿名访问分布式仓库
If anonymous access to your distribution repository is allowed then there is no need to configure authentication. However, while it is technically possible, this is not good practice and is therefore an unlikely scenario
如果允许匿名访问分发存储库,则无需配置身份验证。然而,虽然在技术上是可能的,但这不是好的做法,因此不太可能出现这种情况