Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

dependency management - ivy simple shared repository

I am trying to compile all sub projects of one big project at my company into many jars with managed dependencies, so that not everybody who works at one project only needs to download the latest jars from a shared repository.

ivy seems to be the solution for our problem, because ivy says that it integrates with ant (out build system) very well. But I cant get through the tutorials, they are all somehow more confusing than helpful.

All I want to achieve for the beginning is to have two small Projects. The first one has one class with one method, the second one is just calling this method. The fist project should compile into a jar that is then downloaded by the second project from the shared repository.

Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A multi-module project is described in the documentation:

http://ant.apache.org/ivy/history/latest-milestone/tutorial/multiproject.html

and the source code is available in subversion:

http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/multi-project/

The simplified summary of how it works:

Wrapper build

Invokes each individual module build in the correct order. If Module A depends on module B, then B will be built first:

<project xmlns:ivy="antlib:org.apache.ivy.ant" name="build-all" default="build">

    <!--
    ==========================================================================
    Use the ivy buildlist task to create an ordered list of sub-project builds
    ==========================================================================
    -->
    <target name="build-list">
        <ivy:buildlist reference="build-path">
            <fileset dir="." includes="modules/**/build.xml"/>
        </ivy:buildlist>
    </target>

    <!--
    ==============================
    Invoke targets in sub-projects
    ==============================
    -->
    <target name="build" depends="build-list" description="Invoke build target on sub-projects">
        <subant target="build" buildpathref="build-path" />
    </target>

</project>

For more information see the buildlist documentation.

Module build

Each module will download it's dependencies at the beginning of it's build

<target name="init">
    <ivy:settings file="../../ivysettings.xml"/>
    <ivy:resolve/>
</target>

At at the end, will publish it's built artifacts:

<target name="publish" depends="build" description="Publish module artifacts to the respository">
    <ivy:publish resolver="${publish.resolver}" pubrevision="${publish.revision}" overwrite="true">
        <artifacts pattern="${build.dir}/[artifact].[ext]"/>
    </ivy:publish>
</target>

Don't forget that for all this to work each module must declare what it depends on and what it publishes

<ivy-module version='2.0'>

    <info organisation='com.myorg' module='mymod'/>

    <publications>
        <artifact name="mymod" type="jar"/>
    </publications>

    <dependencies>
         ..
    </dependencies>

</ivy-module>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...