简体   繁体   English

配置jcenter仅用于下载工件,Artifactory用于部署工件

[英]Configure jcenter for only downloading artifacts and Artifactory for deploying artifacts

We have Artifactory setup and we use Maven central repo for downloading artifacts, which are then automatically cached in Artifactory. 我们有Artifactory设置,我们使用Maven central repo下载工件,然后自动缓存在Artifactory中。 We also upload/deploy our own artifacts in Artifactory. 我们还在Artifactory中上传/部署我们自己的工件。

I now want to replace Maven central repo with jcenter and would like to continue using our Artifactory for uploading/deploying our own artifacts and for also caching the jcenter (and any third-party) artifacts. 我现在想用jcenter 替换 Maven central repo,并希望继续使用我们的Artifactory来上传/部署我们自己的工件以及缓存jcenter(以及任何第三方)工件。 I can ask all developers to modify their settings.xml file as it will be a one-time activity so that's not a problem. 我可以要求所有开发人员修改他们的settings.xml文件,因为它将是一次性活动,所以这不是问题。

I saw this link by @helmedeiros which describes making changes in <repositories> and <pluginRepositories> section of settings.xml file. 我在@helmedeiros看到了这个链接,它描述了在settings.xml文件的<repositories><pluginRepositories>部分进行更改。 However, those are the sections where i specify URL for our Artifactory server. 但是,这些是我为Artifactory服务器指定URL的部分。 If i replace my Artifactory URL, then it would mean that i will be able to both fetch and upload artifacts from jcenter which is not what i want. 如果我替换我的Artifactory URL,那么这意味着我将能够从jcenter获取和上传工件,这不是我想要的。

How can i ensure that all developers are only able to pull (NOT deploy/upload) from jcenter and deploy/upload ONLY to Artifactory? 我如何确保所有开发人员只能从jcenter拉取(不部署/上传)并仅部署/上传到Artifactory?

Here's what we have right now in settings.xml: 以下是我们现在在settings.xml中的内容:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
      <id>central</id>
    </server>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
      <id>snapshots</id>
    </server>
  </servers>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>https://inhouse-artifactory/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>https://inhouse-artifactory/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>plugins-release</name>
          <url>https://inhouse-artifactory/artifactory/plugins-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>plugins-snapshot</name>
          <url>https://inhouse-artifactory/artifactory/plugins-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

I will really appreciate any help in this regard. 我真的很感谢这方面的任何帮助。

I have exactly the same question :) 我有完全相同的问题:)

My solution is to create an Artifactory virtual repository (forgerock-third-party-virtual) to cache most of the public artifacts. 我的解决方案是创建一个Artifactory虚拟存储库(forgerock-third-party-virtual)来缓存大多数公共工件。

This virtual repository includes a remote repository based on jcenter: 此虚拟存储库包含基于jcenter的远程存储库:

在此输入图像描述

On the virtual repository, there is no default deployment repository: 在虚拟存储库上,没有默认的部署存储库:

在此输入图像描述

So with this setting, I hope the developers won't be able to push in this virtual repository. 因此,使用此设置,我希望开发人员无法推入此虚拟存储库。

According to the JFrog documentation , you have select one repository in this drop-down to be able to push into a virtual repository. 根据JFrog文档 ,您在此下拉列表中选择了一个存储库,以便能够进入虚拟存储库。

Regarding the deployment settings, we also have a parent pom where we specified our own repositories in the <distributionManagement> section. 关于部署设置,我们还有一个父pom,我们在<distributionManagement>部分中指定了我们自己的存储库。

On my build machines, I've added this profile (in .m2/settings.xml) to cache the artifacts: 在我的构建机器上,我添加了这个配置文件(在.m2 / settings.xml中)来缓存工件:

 <profile>
  <id>force-third-party-repo</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <repositories>
    <repository>
      <id>forgerock-third-party</id>
      <name>ForgeRock Third Party Repository</name>
      <url>http://maven.forgerock.org/repo/forgerock-third-party-virtual</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
  </repositories>
   <pluginRepositories>
    <pluginRepository>
      <id>forgerock-third-party</id>
      <name>ForgeRock Third Party Repository</name>
      <url>http://maven.forgerock.org/repo/forgerock-third-party-virtual</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>
</profile>

I have other settings in this file to declare our own Artifactory repositories (for pushing/pulling our own artifacts) + some Maven credentials. 我在此文件中有其他设置来声明我们自己的Artifactory存储库(用于推/拉我们自己的工件)+一些Maven凭据。

I did some tests with one of our Maven projects and it was working fine. 我用我们的一个Maven项目做了一些测试,它运行正常。

Once the new .m2/settings.xml will be ready, I'll push a template in an internal Artifactory repository, so the developers will be able to get this template with a curl command. 一旦新的.m2 / settings.xml准备就绪,我将在内部Artifactory存储库中推送一个模板,这样开发人员就可以使用curl命令获取此模板。

FYI, this is a POC for the moment. 仅供参考,这是暂时的POC。 We want to move in production with these settings in a few days. 我们希望在几天内使用这些设置进行生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM