tags:

views:

20

answers:

1

In an ant script, I would like to compile only certain packages e.g.

com.example.some_package.foo
com.example.some_package.bar

This is what I want to do, but it doesn't seem to work, because property substitution doesn't seem to work in the <include> tag:

<property name="ROOT_PKG_PATH" location="com/example/some_package"/>

   ...

<target name="compile-client" depends="init">
    <javac srcdir="${srcDir}"
           destdir="${buildDir}"
           debug="on"
           target="1.5"
           classpathref="build.classpath">
        <include name="${ROOT_PKG_PATH}/foo/**" />
        <include name="${ROOT_PKG_PATH}/bar/**" />
    </javac>       
</target>

How can I get around this without having to retype the entire package path of each package?

+1  A: 

Use the value attribute on the property, instead of location:

 <property name="ROOT_PKG_PATH" value="com/example/some_package"/>

Example

I'm able to conditionally compile one of my java classes:

./src/some_package/demo1/Demo.java
./src/some_package/demo2/Demo.java
./build/classes/somepackage/demo1/Demo.class
./build.xml

Using the following ANT file:

<project name="demo" default="compile">

    <property name="prop" value="some_package/demo1"/>

    <target name="compile">
        <mkdir dir="build/classes"/>

        <javac srcdir="src" destdir="build/classes">
            <include name="${prop}/**"/>
        </javac>
    </target>
</project>
Mark O'Connor