【问题标题】:How to configure distinct distributionManagement repositories to plugins and libs?如何为插件和库配置不同的分布管理存储库?
【发布时间】:2015-02-09 13:05:53
【问题描述】:

我正在尝试配置父 POM 的 distributionManagement 部分,以允许将库和插件上传到不同的 Artifactory 存储库,但 maven 3 仅支持 distributionManagement 配置的一部分。

由于我使用不同的存储库来下载插件和库,并且无法为每种类型的工件创建一个父 POM,是否可以配置不同的存储库以让 Artifactory 或简单的 maven 识别工件的类型并部署到正确的存储库?

这是当前的 pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ornanization</groupId>
    <artifactId>corporative-parent</artifactId>
    <packaging>pom</packaging>
    <distributionManagement>
        <repository>
            <id>artifactoryRelease</id>
            <name>artifactory-libs-releases<name>
            <url>${artifactory.url}/libs-release-local</url>
        </repository>
        <snapshotRepository>
            <id>artifactorySnapshot</id>
            <name>artifactory-libs-snapshots</name>
            <url>${artifactory.url}/libs-snapshot-local</url>
        </snapshotRepository>
    </distributionManagement>
</project>

这是我要添加的条目:

<distributionManagement>
    <repository>
        <id>artifactoryRelease</id>
        <name>artifactory-plugins-releases</name>
        <url>${artifactory.url}/plugins-release-local</url>
    </repository>
    <snapshotRepository>
        <id>artifactorySnapshot</id>
        <name>artifactory-plugins-snapshots</name>
        <url>${artifactory.url}/plugins-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>

p.s.:正如 Artifactory 用户指南的this page 中所述,不能仅将构建工件“部署到远程或虚拟存储库”到本地存储库,因此无法让 Artifactory 的布局管理识别工件的类型。

【问题讨论】:

  • 用于下载您的 settings.xml 是您定义下载工件的位置的正确位置,而 distributionManagement 用于上传工件。除此之外,插件和库之间的区别并没有真正意义......
  • 实际上,由于我们在公司环境中,我们已经尝试让本地配置文件尽可能小,因此,尽管有最佳实践,我们仍需要将存储库配置保留在超级POM。但我同意存储库之间不必要的区别。我将尝试与负责 Artifactory 服务器的人员争论以更改此布局。

标签: java maven deployment artifactory


【解决方案1】:

不要使用&lt;distributionManagement&gt;,而是使用Artifactory Maven Plugin

配置的&lt;repoKey&gt; 标记允许您使用变量(环境和项目定义)。只需定义一个代表插件和 lib 存储库的变量,并在相应的项目中设置值。

此外,作为奖励,您将在部署时获得完整的 Build Info BOM

【讨论】:

  • 我更喜欢使用配置文件的解决方案,因为它减少了与存储库服务器的集成耦合。由于我们仍然希望将存储库转移到 Nexus,因此对适应的更改将更少。但是感谢变量条件使用提示,它让我找到了解决方案。
  • 使用 Artifactory 插件最重要的收获是构建集成。你有没有看看你会错过什么? jfrog.com/confluence/display/RTF/Build+Integration
  • 顺便说一句,我还能问你为什么打算搬到 Nexus 吗?
  • 太糟糕了,maven 插件只适用于 Artifactory Pro :(
【解决方案2】:

感谢@JBaruch 提示“定义一个代表插件和 lib 存储库的变量”,我首先对 maven 配置文件进行了研究以从变量激活,并意识到如果某个条件匹配,则可以激活配置文件,所以我最终得到了以下解决方案:

<profile>
    <id>plugins-deploy-artifactory</id>
    <activation>
        <file>
            <exists>target/classes/META-INF/maven/plugin.xml</exists>
        </file>
    </activation>
    <distributionManagement>
        <repository>
            <id>artifactoryRelease</id>
            <name>artifactory-corporativo-releases</name>
            <url>${artifactory.url}/plugins-release-local</url>
        </repository>
        <snapshotRepository>
            <id>artifactorySnapshot</id>
            <name>artifactory-corporativo-snapshots</name>
            <url>${artifactory.url}/plugins-snapshot-local</url>
        </snapshotRepository>
    </distributionManagement>
</profile>

所以当工件是插件时,上面的配置文件被激活,否则,使用默认的分发管理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多