ivy simple shared repository

前提是你 提交于 2019-12-28 04:28:10

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/4106143/ivy-simple-shared-repository

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