Split organization name into nested folders using ivy:retrieve

对着背影说爱祢 提交于 2019-12-24 08:21:37

问题


In ivy I can set a retrieve pattern in order to copy all my dependencies somewhere I want to.

For example:

 <ivy:retrieve pattern="${local-maven2-dir}/[organisation]/[module]/[revision]/[module]-[revision].[ext]" conf="compile" type="jar,bundle" sync="true"/>

I wonder is it possible to treat organization not as a folder, but as a set of nested folders, and keep in deepest folder (which is revision) the jar package, just like jars are stored in maven default repo.

So, basically I want to have jars located in paths like

com/yahoo/platform/yui/yuicompressor/2.4.7

and not like

com.yahoo.platform.yui/yuicompressor/2.4.7

PS: involving groovy scripting counts as a valid solution as well, it's just that I have no idea how can groovy be involved here.


回答1:


Actually, it's quite easy and already documented in Ivy (look near the bottom of the page). You can use [orgPath]:

<ivy:retrieve conf="compile"
    type="jar,bundle"
    sync="true"
    pattern="${local-maven2-dir}/[orgPath]/[module]-[revision].[ext]"/>



回答2:


The following example uses groovy.

David W. offers a far simpler solution, relying on a new "orgPath" pattern token introduced in ivy 2.3.

Example

Produces the following output

├── build
│   ├── com
│   │   └── yahoo
│   │       └── platform
│   │           └── yui
│   │               └── yuicompressor
│   │                   └── 2.4.7
│   │                       └── yuicompressor-2.4.7.jar
│   └── rhino
│       └── js
│           └── 1.6R7
│               └── js-1.6R7.jar
├── build.xml
└── ivy.xml

build.xml

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

    <target name="resolve">
        <ivy:resolve/>
        <ivy:cachepath pathid="build.path" conf="build"/>
    </target>

    <target name="retrieve" depends="resolve">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

        <ivy:artifactproperty conf="compile" name="index.[module].[artifact]" value="[module].[artifact]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].organisation" value="[organisation]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].module" value="[module]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].artifact" value="[artifact]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].revision" value="[revision]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].ext" value="[ext]"/>
        <ivy:artifactproperty conf="compile" name="[module].[artifact].cachefile" value="${ivy.cache.dir}/[organisation]/[module]/jars/[artifact]-[revision].[ext]"/>

        <groovy>
            modules = properties.findAll { it.toString().startsWith("index.") }

            modules.each { key, value ->
                def organisation = properties[value+".organisation"].replace(".","/")
                def module = properties[value+".module"]
                def artifact = properties[value+".artifact"]
                def revision = properties[value+".revision"]
                def ext = properties[value+".ext"]
                def cachefile = properties[value+".cachefile"]

                ant.copy(file:cachefile, tofile:"build/${organisation}/${module}/${revision}/${artifact}-${revision}.${ext}")
            }
        </groovy>
    </target>
</project>

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="build"   description="Build dependencies"/>
        <conf name="compile" description="Compile classpath"/>
    </configurations>

    <dependencies>
        <!-- build dependencies -->
        <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.1.1" conf="build->default"/>

        <!-- compile dependencies -->
        <dependency org="com.yahoo.platform.yui" name="yuicompressor" rev="2.4.7" conf="compile->default"/>
    </dependencies>

</ivy-module>


来源:https://stackoverflow.com/questions/15131012/split-organization-name-into-nested-folders-using-ivyretrieve

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