Antlion
Welcome
License
 
How-To Guides
Getting Started
Libraries
Artifacts
Subprojects
Repositories
Policy Strategies
Format Strings
Extending Antlion
FAQ
 
Tutorials
First Tutorial: Simple
 
Ant Tasks
<artifact>
<libraryDef>
<library>
<library-policy>
inner processors
inner repositories
<library-type>
<library-repository>
<library-urlrepository>
<library-mavenrepository>
<library-repositoryset>
<create-artifact>
<subprojects>
<run-subproject>
<replace-target>
 
Optional Tasks
About optional tasks
RegexpTokenFormatter
 
TOC   Prev   Next  
Compiling the Code

Now that we have fully described the artifacts that we will create with this project, we need to compile them.

Running javac

Using our Antlion-constructed references, we declare the "compile" target in two pieces, one for the core Java files, and one for the unit tests:

  <property name="classes-tests.dir"
    location="${work.dir}/classes-ut" />

  <target name="compile"
      description="Compile the source and test code"
      depends="compile::java, compile::tests"/>
  <target name="compile::java">
    <mkdir dir="${classes.dir}" />
    <javac debug="true" deprecation="true"
        includeAntRuntime="false" srcdir="src/java"
        destdir="${classes.dir}">
      <classpath refid="path.simpleproject.jar.build" />
      <sourcepath>
        <fileset refid="fs-src.simple" />
      </sourcepath>
    </javac>
    <copy todir="${classes.dir}">
      <fileset refid="fs-other.simple" />
    </copy>
  </target>

  <target name="compile::tests">
    <mkdir dir="${classes-tests.dir}" />
    <javac debug="true" deprecation="true"
        includeAntRuntime="false" srcdir="src/tests"
        destdir="${classes-tests.dir}">
      <classpath refid="path.simpleproject-tests.jar.build" />
      <sourcepath>
        <fileset refid="fs-src.simple-tests" />
      </sourcepath>
    </javac>
    <copy todir="${classes-tests.dir}">
      <fileset refid="fs-other.simple-tests" />
    </copy>
  </target>

This will compile the code, and copy the non-Java files into the classes directories. We use the Antlion-generated identifiers for the depends classpaths, but use the fileset IDs we explicitly specified for the source files. Note that even though we used the <sourcepath> elements, we still need to declare the srcdir.

Note that the "compile::tests" target does not declare a dependency upon the "compile::java" target. This allows a knowledgable user to spend their valuable seconds on building the "compile::java" only when they need to; that is, if they are working on the unit tests, they shouldn't spend their time running a task that isn't necessary. Also, since only the "compile" target has a description, the -projecthelp argument to Ant will only tell users about the "compile" target.


Creating The Jars

Since we just created a directory that's nicely organized for a jar file, we might as well create the jar files now, one for each declared artifact:

  <target name="dist"
      description="create the distributable files"
      depends="compile, dist::java, dist::tests" />
  <target name="dist::java">
    <mkdir dir="${dist.dir}" />
    <jar destfile="${artifact.simpleproject.jar}"
          basedir="${classes.dir}">
      <manifest>
        <attribute name="Class-Path"
            value="${mfcp.simpleproject.jar}" />
      </manifest>
    </jar>
  </target>
  <target name="dist::tests">
    <mkdir dir="${dist.dir}" />
    <jar destfile="${artifact.simpleproject-tests.jar}"
        basedir="${classes-tests.dir}" />
  </target>

Even though the individual distribution targets have a dependency upon the compiled source, we only declare this dependency for the owning "dist" target. This allows a knowledgable user to only build what they need to build. Our artifacts, however, require a tighter set of dependencies to work correctly, so we have those as separate targets, with the full dependency list.

  <target name="artifact::jar"
      depends="compile::java, dist::java" />
  <target name="artifact::test-jar"
      depends="compile::java, compile::tests, dist::tests" />

Here, we force the correct dependencies, even with the tests, since the java code must be compiled before the tests.



TOC   Prev   Next  
Document version $Revision: 1.6 $ $Date: 2005/10/31 04:37:58 $

SourceForge Logo
Copyright © 2004-2006, The Antlion Project