Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27266

approch for inter-project dependencies

I have a console-based build system that's using Ant and Ivy and would like to avoid using Maven. I fetch my project's external dependencies using Ivy. My question is how best to handle my internal project dependencies. I.e. I build a number of library files (JARs) on which my modules are based and which unlikely to be used in another context. So these internal project dependencies are simply captured by build.xml files directly identifying the location of the needed JARs via relative paths (since everything's under the same source tree in the repository). E.g. I have Ant "code" like this:

<path id = "compile.classpath">
  <fileset dir="${internal-project-dependency-a.dir}">
    <include name ="*.jar"/>
  </fileset>
  <fileset dir="${internal-project-dependency-b.dir}">
    <include name ="*.jar"/>
  </fileset>
  <fileset dir="${internal-project-dependency-c.dir}">
    <include name ="*.jar"/>
  </fileset>
</path>

My question is: is the above approach acceptable (from a best-practice point of view) or should I instead package and publish even my internal project dependencies in some lightweight "local-only" Ivy repository (if there's such a thing)? The way I've setup my system anyone with Ivy and Ant can checkout my sources from github and build everything from the console without needing to configure any other kind of Ivy repository information and I'd like to keep that property.

Upvotes: 0

Views: 89

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77941

Ivy supports different kinds or repositories, described in the documentation.

  • local
  • shared
  • public

Without customization these are located under your "~/.ivy2" directory. So, I would recommend configuring each builds to publish to your local repository and simply reference dependencies as normal. All you need to do is ensure that on a fresh machine the build order is correct, so that the local repo is populated in the correct order (See the buildlist task).

Using the local repo is not very different from referencing the jars in known relative locations. It does have the benefit of making each project decoupled from the other.

Example

├── build.xml
└── ivy.xml

Project publishes 3 files to the local repository:

$ find ~/.ivy2/local -type f
/home/mark/.ivy2/local/myorg/hello/1.0/ivys/ivy.xml.sha1
/home/mark/.ivy2/local/myorg/hello/1.0/ivys/ivy.xml
/home/mark/.ivy2/local/myorg/hello/1.0/ivys/ivy.xml.md5
/home/mark/.ivy2/local/myorg/hello/1.0/docs/English.txt.md5
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Spanish.txt.sha1
/home/mark/.ivy2/local/myorg/hello/1.0/docs/English.txt.sha1
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Irish.txt.sha1
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Spanish.txt.md5
/home/mark/.ivy2/local/myorg/hello/1.0/docs/English.txt
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Spanish.txt
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Irish.txt.md5
/home/mark/.ivy2/local/myorg/hello/1.0/docs/Irish.txt

build.xml

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

    <target name="init">
      <ivy:resolve/>
    </target>

    <target name="build" depends="init">
      <mkdir dir="build"/>
      <echo file="build/English.txt">Hello world</echo>
      <echo file="build/Irish.txt">Dia dhuit</echo>
      <echo file="build/Spanish.txt">Hola mundo</echo>
    </target>

   <target name="publish" depends="clean,build">
      <ivy:publish pubrevision="1.0" status="release" resolver="local" >
         <artifacts pattern="build/[artifact].[ext]"/>
      </ivy:publish>
   </target>

    <target name="clean" description="Cleanup build files">
        <delete dir="build"/>
    </target>

</project>

ivy.xml

<ivy-module version="2.0">
  <info organisation="myorg" module="hello"/>
  <publications>
    <artifact name="English" ext="txt" type="doc"/>
    <artifact name="Irish" ext="txt" type="doc"/>
    <artifact name="Spanish" ext="txt" type="doc"/>
  </publications>
</ivy-module>

Upvotes: 1

Related Questions