java – ivy:使用分类器从maven安装

前端之家收集整理的这篇文章主要介绍了java – ivy:使用分类器从maven安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试常春藤:从maven安装jogl和gluegen到我当地的存放处.我无法正确安装本机依赖项.

我的ivysettings是

<ivysettings>
    <settings defaultResolver="central"
            defaultConflictManager="all"
    />
    <caches defaultCacheDir="${ivy.cache.dir}"
            artifactPattern="[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]" 
    />
    <resolvers>
        <ibiblio name="central" m2compatible="true"
                 pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
        />
        <filesystem name="depository">
            <ivy pattern="${dest.repo.dir}/[organisation]/[module]/ivys/ivy-[revision](-[classifier]).xml" />
            <artifact pattern="${dest.repo.dir}/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]" />
        </filesystem>
    </resolvers>
</ivysettings>

我的安装目标是

<ivy:install settingsRef="ivy.settings" 
    organisation="org.jogamp.jogl" module="jogl-all-main" revision="2.1.5-01"
    from="${from.resolver}" to="${to.resolver}" transitive="true" overwrite="true" />

其中from.resolver是中心,to.resolver是存放处.

分类器例如是native-windows-i586,native-linux-armv6等.有问题的pom文件是在http://repo1.maven.org/maven2/org/jogamp/jogl/jogl-all-main/2.1.5-01/jogl-all-main-2.1.5-01.pom

我正确地解决了jogl-all-main.解析依赖关系后,只解析pom文件中的最后一个,即jogl-all-2.1.5-01-natives-windows-i586.jar.有没有办法使用常春藤:安装任务从maven中央存储库安装到我的本地存储库?

解决方法

简短的回答是,ivy对与Maven模块关联的其他工件文件支持非常有限.

我为重复自己而道歉,但最好建议您运行Maven存储库管理器来缓存远程Maven存储库.这避免了在不同格式之间进行折衷的必要性.

这个限制背后的起源

远程Maven POM没有明确列出其模块的工件.可能的分类器值的数量没有限制….可以做出的唯一假设是模块可能包含额外的“javadoc”或“sources”工件. (在开源项目中很常见).

Maven documentation描述了分类器如下:

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.

常春藤存储库的工作方式不同.模块的常春藤文件有一个明确列出模块内容publications section.

为了更深入地了解常春藤如何解释Maven存储库,我建议以下发布.

> How are maven scopes mapped to ivy configurations by ivy

可能的解决方法

以下示例使用retrieve任务将下载的依赖项写入所需的存储库格式.结果是缺少校验和文件,但这可能无关紧要.

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

笔记:

>需要明确列出要下载的每个所需工件.如上所述,只能假设“javadoc”和“sources”分类器.

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>

猜你在找的Java相关文章