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

查看:36
本文介绍了使用 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 文件和 Maven 设置文件将存储库指定给 Artifactory,但几乎没有成功:

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 将发布而不是快照发布到 Artifactory 的 libs-release-local 存储库中,一切都会如您所愿地解决.此外,如果我将唯一时间戳指定为依赖项版本的一部分(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.

推荐答案

已在此处回答了从 ivy 发布到 Nexus 存储库的问题:

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

如何使用 ivy 发布 3rdparty 工件和联系

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

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>

注意事项:

  • 对于 artifactory,凭据 realm 参数将是Artifactory Realm".
  • For artifactory the credentials realm parameter would be "Artifactory Realm".

最后是构建逻辑本身.

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

注意事项:

  • prepare 目标使用 makepom 任务.
  • ivy deliver 任务是可选的,但如果您的 ivy 文件中有任何动态修订(latest.integration、latest.release),建议您这样做.
  • publish 目标发布到您的设置文件中定义的 nexus-deploy 解析器.
  • ${publish.revision} 属性在构建的其他地方设置.我建议阅读有关 ivy 的 buildnumber 任务
  • 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天全站免登陆