2015-02-09 307 views
0

我正在尝试配置父POM的distributionmanagement部分,以便将库和插件上传到不同的Artifactory存储库,但maven 3仅支持distributionManagement配置的一部分。如何将不同的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> 

PS:在Artifactory的的用户指南this page如说,它不是可能只是将本地存储库的构建工件部署到远程或虚拟存储库,所以Artifactory的布局管理无法识别工件的类型。

+1

下载您的settings.xml是您定义下载工件的位置的正确位置,而distributionManagement用于上传工件。除此之外,插件和库之间的区别并不是真的有意义...... – khmarbaise 2015-02-09 15:09:54

+0

实际上,因为我们处于企业环境中,我们尝试让本地配置文件尽可能小,所以尽管采用了最佳做法,但我们将需要保留超级POM上的存储库配置。 但我同意存储库之间的不必要的区别。我会尝试与负责Artifactory服务器的人员争论,以改变这种布局。 – 2015-02-11 16:42:03

回答

0

感谢@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> 

所以当神器是一个插件,上面的配置文件被激活,否则,默认distributionManagement使用。

2

只是不要使用<distributionManagement>而是使用Artifactory Maven Plugin来代替。

该配置的<repoKey>标签允许您使用变量(包括环境和项目定义)。只需定义一个代表plugin和lib存储库的变量,并在相应的项目中设置这些值即可。

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

+0

我更喜欢使用配置文件的解决方案,因为它保持与存储库服务器的集成不太耦合。由于我们仍然希望将存储库转换为Nexus,因此对适应性的更改将会变得更少。但是,感谢变量条件使用提示,它让我变成了解决方案。 – 2015-02-11 17:04:56

+0

使用Artifactory插件最重要的收益是构建集成。你看看你会错过什么吗? http://www.jfrog.com/confluence/display/RTF/Build+Integration – JBaruch 2015-02-12 10:01:21

+0

顺便说一句,我也可以问你为什么打算迁移到Nexus? – JBaruch 2015-02-12 10:02:27