Publish SNAPSHOT artifacts to Maven using IVY - what's the magic?

核能气质少年 提交于 2019-11-29 07:53:30
Mark O'Connor

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

how to publish 3rdparty artifacts with ivy and nexus

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

Example

ivy.xml

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>

Notes:

  • The other example is more complicated, demonstrating how addtional artifacts can be added to the Maven module.

ivysettings.xml

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>

Notes:

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

build.xml

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>

Notes:

  • 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

Note on artifactory

Artifactory appears to have some built-in support for ivy

If you are already going to migrate to Maven I would suggest to check out the Aether Ant Tasks, which are the replacement for the old (and now pretty much deprecated) Maven Ant Tasks. Using that will be exposing all the needed Maven dependency handling features you need for your task..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!