A simple ant build script that supports src / and test /?

I am currently using the IDE for all of my team and unit tests. Now I need to use ant. I found some simple ant build.xml scripts, but they did not support a separate Junit / dit test. My projects are structured as follows:

  src /
   com / foo /
   com / bar /

 test / - Mirror of src /, with all * Test.java files.
   com / foo / 
   com / bar /

 lib / - All Java libs, including junit 4.

How can I build a small ant script that creates my src / and test / Java classes and then runs all my JUnit tests?

+4
source share
2 answers

I define <path> elements for each target.

This is an excerpt from my build file, you will have to adapt some paths and properties, but you can get the idea:

 <path id="src.path"> <pathelement path="src/"/> </path> <path id="compile.path"> <path refid="src.path"/> <fileset dir="lib/"> <include name="**/*.jar"/> </fileset> </path> <path id="unit.test.path"> <path refid="compile.path"/> <pathelement path="test/"/> </path> <target name="compile"> <javac destdir="bin"> <src path="src"/> <classpath refid="compile.path"/> </javac> </target> <target name="compileUnitTests" depends="compile"> <javac srcdir="test/" destdir="bin"> <classpath refid="unit.test.path"/> </javac> </target> <target name="runUnitTests" depends="compileUnitTests"> <junit printsummary="yes" haltonfailure="no"> <jvmarg value="-Dfile.encoding=UTF-8"/> <classpath refid="unit.test.path"/> <formatter type="xml"/> <batchtest fork="yes" todir="${this.report}"> <fileset dir="test"> <include name="${test.pattern}"/> <exclude name="**/AllTests.class"/> <exclude name="**/*$*.class"/> </fileset> </batchtest> </junit> </target> 

And if you need to clarify this for your needs, as cotton says, go read the ant task documents. Using ant with your specific directory structure requires some knowledge of this tool, don't expect you to easily find ready-made examples that just work with your exact requirements.

+6
source

I do not understand the question. Are you asking how to set a default goal? Choose which target to run on execution, or you just donโ€™t know how to write build.xml files? This is actually not so difficult. See http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html and http://ant.apache.org/manual/

0
source

Source: https://habr.com/ru/post/1335684/


All Articles