I have an Ant build script to generate some classes. The process requires an external library. Since I need this task for a lot of different modules I don’t want to copy the lib everytime and I don’t want to reference it localy as that would require all developers to download the lib first.
How do I reference and include an external resource?
This is my setup so far
<project name="generate" basedir=".">
<property name="src" location="src/main/java"/>
<property name="generated" location="target/classes"/>
<property name="build" location="src/main/java"/>
<path id="cp">
<fileset dir="path/to/lib" includes="**/querydsl-jpa-2.2.3-apt-one-jar.jar"/>
<fileset dir="path/to/.m2" includes="**/*.jar"/>
</path>
<target name="compile" >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" classpathref="cp" includeantruntime="false">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="com.mysema.query.apt.QuerydslAnnotationProcessor"/>
<compilerarg value="-s"/>
<compilerarg value="${generated}"/>
</javac>
<!-- compilation -->
<javac classpathref="cp" destdir="${build}" includeantruntime="false">
<src path="${src}"/>
<src path="${generated}"/>
</javac>
</target>
</project>
Now I have the querydsl-jpa-2.2.3-apt-one-jar.jar at some remote location and I also want to reference our internal maven repository instead of the local .m2 directory, so I need to reference remote locations and include the libraries from there.
I would suggest you use the Apache Ivy Ant plug-in. It can help you in two ways:
Developers using your project will only require the Ivy jar installed into one of the following locations:
build.xml
The Ivy resolve task downloads (and caches) dependencies (found in the ivy.xml file). The cachepath task automatically populates the classpath:
ivy.xml
Dependencies are declared here:
The querydsl-jpa-2.2.3-apt-one-jar.jar jar is special needs an additional classifier specification. If it was a Maven dependency it would be declared as follows:
ivysettings.xml
Ivy can be configured to use your Maven repository (Just like a Maven client):