Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modularizing classpaths in ant scripts (e.g. via refid)

Tags:

java

build

ant

Since my ant file is quite complex, I want to modularize my classpath-elements.

Currently, I use refid in the following way:

<path id="compile.classpath">
  <pathelement path="foo"/>
  <!-- ... -->
</path>

<path id="test.classpath">
  <path refid="compile.classpath"/>
  <pathelement path="bar"/>
  <!-- ... -->
</path>

<!-- ... -->

    <javac>
        <classpath refid="compile.classpath"/>
    </javac>

    <junit>
        <!-- ... -->
        <classpath>
             <path refid="test.classpath"/>
             <path path="bazz"/>
        </classpath>
    </junit>

<!-- ... -->

Is this a sensible approach? Or is there a better one?

Is it ok to use a path-id (compile.classpath) for a classpath-refid (in <javac>)? (It currently works, but refid does require the elements to be of the same type. Since path and classpath are both path-like structures, are they of the same type?)

like image 581
DaveFar Avatar asked Feb 01 '12 17:02

DaveFar


Video Answer


1 Answers

I successfully used this approach at a previous job and it was really the only way I could keep everything sane.

I eventually took things a step further an put all my third-party library definitions in a separate ext-libs.xml file since several of them were multi-jar libraries and making sure I had all of them contained in my final war files was getting to be a giant hassle. That way, in my main build.xml (and others) I could refer to, say, lib.jaxb and not have to worry that I'd updated the version numbers in the files names everywhere.

You've already figured out the trick of extending your compile classpath to make your test classpath, so you're on the right track.

In short, press on.

like image 185
Argyle Avatar answered Sep 28 '22 05:09

Argyle