使用IVY将SNAPSHOT工件发布到Maven - 有什么魔法? [英] Publish SNAPSHOT artifacts to Maven using IVY - what's the magic?

查看:254
本文介绍了使用IVY将SNAPSHOT工件发布到Maven - 有什么魔法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have a slight convoluted situation...

在大多数情况下,我们一直在使用IVY和ANT来管理我们的构建和依赖关系。现在公司正在使用Maven。我们有一组名为公共图书馆的项目,这些项目被几个核心产品所使用。

For the most part we've been using IVY and ANT to manage our builds and dependencies. Now the company is moving towards using Maven. We have a set of projects called common libraries which are used by several of the core products.

通用库使用IVY并发布到IVY存储库。我们还需要为我们的新Maven项目提供共同的库。所以当公共图书馆建成并发布时,我修改了发布到Maven(Artifactory)以及IVY的脚本。以下是发布构建的IVY项目时现在调用的两个目标:

Common libraries use IVY and are published to an IVY repository. We also need to make common libraries available for our new Maven projects. So when common libraries get built and published, I've modified the script to publish to Maven (Artifactory) as well IVY. Here are the two targets that now get called when publishing the built IVY projects:

<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>

这里是详细说明解析器的IVY设置:

And here is the IVY settings detailing the resolvers:

<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>

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

This kind of works in that I now see the common library jars within Artifactory, with SNAPSHOT substituted for the unique timestamp. However, the source jar and the IVY xml file doesn't have SNAPSHOT substituted. Also, no POM file is being generated (though I dont know if this is necessary.

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

So this appears to be okay, though there are questions around the need for the POM file and the version naming of the IVY xml and the source jar. However, when I now proceed to specify a dependency from one of the Maven projects to one of the SNAPSHOT versions of the common library projects, it complains that it cannot resolve the dependency:


缺少工件com.smartstream.common_library:common_library_dao:jar:4.0.0.5-4-SNAPSHOT:compile

Missing artifact com.smartstream.common_library:common_library_dao:jar:4.0.0.5-4-SNAPSHOT:compile

我已经尝试通过POM文件将仓库指定为Artifactory,而通过Maven设置文件将无法成功:

I've tried specifying the repositories to Artifactory via the POM file and via the Maven settings file will little success:

<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>

奇怪的是,如果我将IVY发布到SNAPSHOT,而不是将其发布到libs-版本本地的Artifactory存储库,所有解决方案都符合您的期望。另外,如果我将唯一时间戳指定为依赖关系版本(SNAPSHOT的另外一个),那么它也会解析它。所以这表明,Maven项目能够解决Artifactory,只是一些事情与SNAPSHOT版本不一致。

What is strange is if I get IVY to publish a release as opposed to a SNAPSHOT into the libs-release-local repository of Artifactory, all resolves as you'd expect. Also, if I specify the unique timestamp as part of the dependency version (the substiute of SNAPSHOT), it also resolves it. So this shows that the Maven projects are able to resolve against Artifactory, just that something is going amiss with SNAPSHOT versions.

我已经挖掘出高低低的希望在这个问题上。如果您能提供任何见解,那将受到高度评价。

I've dug around high and low with little hope on this issue. If you can provide any insight, that'll be highly appreciated.

推荐答案

从常春藤出版到Nexus仓库已经在这里回答:

Publishing to a Nexus repository from ivy has been answered here:

如何使用ivy和nexus发布第三方工件

该答案可能太全面。相关部分标题为常春藤解决方案。我将在这里总结一下:

That answer is possibly too comprehensive. The relevent section is titled "Ivy Solution". I'll summarise it here:

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

You'll need a publications section stating that you're publishing a jar and it's associated 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>

注意:


  • 另一个例子比较复杂,说明了如何在Maven模块中添加附加工件。

我正在使用 ibiblio 解析器,Maven 2兼容性打开。根据我的经验,这是在ivy中配置Maven仓库的最佳方法。

I'm using ibiblio resolvers, with Maven 2 compatibility switched on. In my experience this is the best way to configure a Maven repository in ivy.

<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>

注意:


  • 对于工件,凭证 realm 参数将是Artifactory Realm。

  • For artifactory the credentials realm parameter would be "Artifactory Realm".

最后是构建逻辑本身。

Finally the build logic itself.

<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>

注意:


  • 准备目标使用 makepom 任务。

  • 常春藤交付任务是可选,但如果您的ivy文件中有任何动态修订(latest.integration,latest.release),建议您使用。

  • 发布目标发布到 nexus-deploy 解析器在您的设置文件中定义。

  • $ {publish.revision} 属性设置在构建的其他位置。我建议您阅读有关常春藤编号任务的信息

  • The prepare target generates the POM using the makepom task.
  • The ivy deliver task is optional, but recommended in case you have any dynamic revisions (latest.integration, latest.release) in your ivy file.
  • The publish target publishes to the nexus-deploy resolver defined in your settings file.
  • The ${publish.revision} property is set elsewhere in the build. I'd recommend reading about ivy's buildnumber task

Artifactory似乎有一些建立常春藤支持

Artifactory appears to have some built-in support for ivy

这篇关于使用IVY将SNAPSHOT工件发布到Maven - 有什么魔法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆