ivy:install from maven with classifiers

半城伤御伤魂 提交于 2019-12-04 05:33:31
Mark O'Connor

The short answer is that ivy has very limited support for additional artifact files associated with a Maven module.

I apologise for repeating myself, but you are best advised to run a Maven repository manager to cache remote Maven repositories. This avoids the necessity to compromise between differing formats.

Origin behind this restriction

A remote Maven POM does not explicitly list its module's artifacts. There is no limit on the number of possible classifier values.... The only assumption that can be made is that the module might contain an additional "javadoc" or "sources" artifact. (Common in open source projects).

The Maven documentation describes classifiers as follows:

classifier: The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

As a motivation for this element, consider for example a project that offers an artifact targeting JRE 1.5 but at the same time also an artifact that still supports JRE 1.4. The first artifact could be equipped with the classifier jdk15 and the second one with jdk14 such that clients can choose which one to use.

Another common use case for classifiers is the need to attach secondary artifacts to the project’s main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.

Ivy repositories work differently. The module's ivy file has a publications section that explicitly lists the module's contents.

For a greater insight into how ivy interprets Maven repositories I would recommend the following posting.

Possible work-around

The following example uses the retrieve task to write out the downloaded dependencies into the desired repository format. The result is missing checksum files, but that may not matter.

├── build.xml
├── ivy.xml
└── target
    └── repo
        └── org
            └── jogamp
                └── jogl
                    ├── jogl-all
                    │   └── 2.1.5-01
                    │       ├── jogl-all-2.1.5-01.jar
                    │       ├── jogl-all-2.1.5-01-javadoc.jar
                    │       ├── jogl-all-2.1.5-01-natives-android-armv6.jar
                    │       ├── jogl-all-2.1.5-01-natives-linux-amd64.jar
                    │       ├── jogl-all-2.1.5-01-natives-linux-armv6hf.jar
                    │       ├── jogl-all-2.1.5-01-natives-linux-armv6.jar
                    │       ├── jogl-all-2.1.5-01-natives-linux-i586.jar
                    │       ├── jogl-all-2.1.5-01-natives-macosx-universal.jar
                    │       ├── jogl-all-2.1.5-01-natives-solaris-amd64.jar
                    │       ├── jogl-all-2.1.5-01-natives-solaris-i586.jar
                    │       ├── jogl-all-2.1.5-01-natives-windows-amd64.jar
                    │       ├── jogl-all-2.1.5-01-natives-windows-i586.jar
                    │       └── jogl-all-2.1.5-01-sources.jar
                    └── jogl-all-main
                        └── 2.1.5-01
                            ├── jogl-all-main-2.1.5-01.jar
                            ├── jogl-all-main-2.1.5-01-javadoc.jar
                            └── jogl-all-main-2.1.5-01-sources.jar

ivy.xml

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="repo" description="Artifacts that make up local repository"/>
    </configurations>

    <dependencies>
        <dependency org="org.jogamp.jogl" name="jogl-all-main" rev="2.1.5-01" conf="repo->default">
            <artifact name="jogl-all-main"/>
            <artifact name="jogl-all-main" e:classifier="sources"/>
            <artifact name="jogl-all-main" e:classifier="javadoc"/>
        </dependency>

        <dependency org="org.jogamp.jogl" name="jogl-all" rev="2.1.5-01" conf="repo->default">
            <artifact name="jogl-all"/>
            <artifact name="jogl-all" e:classifier="sources"/>
            <artifact name="jogl-all" e:classifier="javadoc"/>
            <artifact name="jogl-all" e:classifier="natives-android-armv6"/>
            <artifact name="jogl-all" e:classifier="natives-linux-amd64"/>
            <artifact name="jogl-all" e:classifier="natives-linux-armv6"/>
            <artifact name="jogl-all" e:classifier="natives-linux-armv6hf"/>
            <artifact name="jogl-all" e:classifier="natives-linux-i586"/>
            <artifact name="jogl-all" e:classifier="natives-macosx-universal"/>
            <artifact name="jogl-all" e:classifier="natives-solaris-amd64"/>
            <artifact name="jogl-all" e:classifier="natives-solaris-i586"/>
            <artifact name="jogl-all" e:classifier="natives-windows-amd64"/>
            <artifact name="jogl-all" e:classifier="natives-windows-i586"/>
        </dependency>
    </dependencies>

</ivy-module>

Notes:

  • Need to explicitly list each desired artifact to be downloaded. As stated eariler only the "javadoc" and "sources" classifiers can be assumed.

build.xml

<project name="demo" default="install" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ================
    Build properties
    ================
    -->
    <property name="repo.dir" location="target"/>

    <!--
    ===========
    Build repo
    ===========
    -->
    <target name="install" description="Download and install dependencies">
        <ivy:retrieve pattern="${repo.dir}/[conf]/[orgPath]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
    </target>

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