使用IVY将SNAPSHOT工件发布到Maven - 这有什么神奇之处?

And*_*dyF 4 dependencies repository ivy artifactory maven

我们有一个轻微的错综复杂的情况......

在大多数情况下,我们一直在使用IVY和ANT来管理我们的构建和依赖项.现在该公司正在转向使用Maven.我们有一组称为公共库的项目,这些项目被几个核心产品使用.

公共库使用IVY并发布到IVY存储库.我们还需要为我们的新Maven项目提供公共库.因此,当公共库被构建和发布时,我已经修改了脚本以发布到Maven(Artifactory)以及IVY.以下是发布构建的IVY项目时现在调用的两个目标:

<target name="publish-ivyrepo" depends="load-ivysettings">
    <ivy:resolve file="ivy.xml"  /> 
    <ivy:publish 
        module="${ant.project.name}"
        artifactspattern="${dist.dir}/[artifact].[ext]" 
        resolver="integration" 
        pubrevision="${build.version}" 
        status="integration"    
        overwrite="true"
        update="true"/>
</target>

<target name="publish-artifactory" depends="load-ivysettings">
    <ivy:resolve file="ivy.xml"  /> 
    <ivy:publish 
        module="${ant.project.name}"
        artifactspattern="${dist.dir}/[artifact].[ext]" 
        resolver="artifactory" 
        pubrevision="${build.version}-SNAPSHOT" 
        status="integration"    
        overwrite="true"
        update="true"/>
</target>
Run Code Online (Sandbox Code Playgroud)

以下是详细说明解析器的IVY设置:

<sftp name="integration" checkmodified="true" changingPattern=".*" host="host" user="ivy" userPassword="abc">
  <ivy pattern="${ivy.integration.default.root}/${ivy.public.default.ivy.pattern}"/>
  <artifact pattern="${ivy.integration.default.root}/${ivy.public.default.artifact.pattern}"/>
</sftp>
<url name="artifactory" checkmodified="false" changingPattern=".*" m2compatible="true">
  <ivy pattern="http://server/artifactory/libs-snapshot-local/${maven.default.ivy.pattern}"/>
  <artifact pattern="http://server/artifactory/libs-snapshot-local/${maven.default.artifact.pattern}"/>
</url>
Run Code Online (Sandbox Code Playgroud)

这种作品我现在在Artifactory中看到了常见的库jar,SNAPSHOT代替了唯一的时间戳.但是,源jar和IVY xml文件没有替换SNAPSHOT.此外,没有生成POM文件(虽然我不知道这是否有必要.

所以这似乎没问题,尽管有关于POM文件的需求以及IVY xml和源jar的版本命名的问题.但是,当我现在继续指定从一个Maven项目到公共库项目的SNAPSHOT版本之一的依赖项时,它抱怨它无法解析依赖项:

缺少神器com.smartstream.common_library:common_library_dao:罐子:4.0.0.5-4-快照:编译

我已经尝试通过POM文件为Artifactory指定存储库,并且通过Maven设置文件几乎没有成功:

<repository>
    <id>test</id>
    <name>simple test</name>
    <url>http://server/artifactory/libs-snapshot</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我让IVY将一个版本发布而不是SNAPSHOT发布到版本库的libs-release-local存储库中,那么所有内容都会按照您的预期进行解析.此外,如果我将唯一时间戳指定为依赖项版本(SNAPSHOT的替代)的一部分,它也会解析它.所以这表明Maven项目能够解决Artifactory,只是SNAPSHOT版本出现问题.

我在这个问题上几乎没有希望地挖掘高低.如果您能提供任何见解,那将非常感激.

Mar*_*nor 7

从ivy发布到Nexus存储库已在这里得到解答:

如何使用常春藤和nexus发布第三方文物

答案可能太全面了.相关部分的标题是"常春藤解决方案".我在这里总结一下:

的ivy.xml

您需要一个出版物部分,说明您正在发布一个jar并且它是相关的POM:

<ivy-module version='2.0'>
    <info organisation="com.myspotonontheweb" module="donaldduck"/>

    <publications>
        <artifact name="donaldduck" type="jar"/>
        <artifact name="donaldduck" type="pom"/>
    </publications>

    ..
    ..

</ivy-module>
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 另一个例子更复杂,演示了如何将附加工件添加到Maven模块.

ivysettings.xml

我正在使用ibiblio解析器,打开了Maven 2兼容性.根据我的经验,这是在常春藤中配置Maven存储库的最佳方式.

<ivysettings>
    <settings defaultResolver="nexus-central"/>
    <credentials host="somehost" realm="Sonatype Nexus Repository Manager" username="????" passwd="????"/>
    <resolvers>
        <ibiblio name="nexus-central" root="http://somehost/nexus/content/repositories/central/" m2compatible="true"/>
        <ibiblio name="nexus-deploy" root="http://somehost/nexus/content/repositories/repo" m2compatible="true"/>
    </resolvers>
</ivysettings>
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 对于神器,凭证领域参数将是"Artifactory Realm".

build.xml文件

最后是构建逻辑本身.

<target name="prepare" description="Generate POM">
    <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/>
    <ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/donaldduck.pom"/>
</target>

<target name="publish" depends="init,build,prepare" description="Upload to Nexus">
    <ivy:publish resolver="nexus-deploy" pubrevision="${publish.revision}" overwrite="true" publishivy="false" >
        <artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
    </ivy:publish>
</target>
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 准备目标产生使用了POM makepom任务.
  • 常春藤传递任务是可选的,但建议您在常春藤文件中进行任何动态修订(latest.integration,latest.release).
  • 发布目标发布到关系部署在你的设置文件中定义解析器.
  • $ {} publish.revision属性在构建其他地方设置.我建议阅读有关常春藤的buildnumber任务

关于神器的注意事项

Artifactory似乎对常春藤有一些内置的支持

  • 解释的很好,很有帮助。但是这个方案还是无法上传pom.xml。为了实现这一点,我不得不将 `&lt;artifact name="donaldduck" ext="pom" type="pom" /&gt;` 添加到 `&lt;ivy:publish&gt;` 目标的内部元素。它在这里描述: [http://theholyjava.wordpress.com/2011/01/26/using-ivy-with-pom-xml/] ,但老实说我不明白这是如何工作的(奇怪的是,我生成了 pom到子文件夹中,但不必在 `&lt;artifact`&gt; 元素中声明此子文件夹) (2认同)

Man*_*ser 0

如果您已经打算迁移到 Maven,我建议您查看Aether Ant Tasks,它是旧的(现在几乎已弃用的)Maven Ant Tasks 的替代品。使用它将暴露您的任务所需的所有 Maven 依赖项处理功能。