AntRun is a template structure for Java projects. Through its comprehensive
Ant build script, it supports automated execution of unit tests, generation
of Javadoc
documentation and code coverage reports (with
JaCoCo), and download and installation
of JAR dependencies as specified in an external, user-definable XML file.
It also includes a boilerplate .gitignore
file suitable for an Eclipse or
IntelliJ project.
All this is done in a platform-independent way, so your build scripts should work on MacOS, Linux and Windows.
- First make sure you have the following installed:
- The Java Development Kit (JDK) to compile. AntRun was developed and tested on version 8 of the JDK, but it is probably safe to use any later version.
- Ant to automate the compilation and build
process. For Debian-based systems, this corresponds to two packages:
ant
andant-optional
.
-
Download the AntRun template from GitHub or clone the repository using Git:
[email protected]:sylvainhalle/AntRun.git
-
Override any defaults, and specify any dependencies your project requires by editing
config.xml
. In particular, you may want to change the name of the Main class. -
Start writing your code in the
Source/Core
folder, and your unit tests inSource/CoreTest
. Optionally, you can create an Eclipse workspace out of theSource
folder, withCore
andCoreTest
as two projects within this workspace. -
Use Ant to build your project. To compile the code, generate the Javadoc, run the unit tests, generate a test and code coverage report and bundle everything in a runnable JAR file, simply type
ant all
on the command line. -
If dependencies were specified in step 4 and are not present in the system, type
ant download-deps
to automatically download and install them before compiling.
Otherwise, use one of the many tasks that are predefined.
In doubt, execute
$ ant -p
from the project's top folder to get the list of all available targets.
The default task. Currently applies jar
.
Compiles the project; checks and downloads dependencies, if any of them is not fulfilled.
Compiles the unit tests. Tests can use either JUnit 4 or JUnit 5. They are run with JUnit 5 (with the "vintage" engine in the case of tests written for version 4).
Compiles the project, generates the Javadoc and creates a runnable JAR,
including the sources and the documentation (and possibly the project's
dependencies, see download-deps
below).
Performs tests with JUnit. A summary of the execution of the tests is also printed at the console. The format of this summary depends on the version of Ant.
Performs tests with JUnit. Performs tests with jUnit, but without using the
junitlauncher
task that is supported only in Ant 1.10.6 onwards. This results
in less detailed reports. It is recommended to use only on versions of Ant
prior to 1.10.6.
Generates unit test and code coverage reports (with JaCoCo).
The unit test report (in HTML format) is available in the tests/junit
folder (which will be created if it does not exist). The code coverage
report is available in the tests/coverage
folder.
Alternately, you can call junit-report
and jacoco-report
to perform
these tasks individually.
Note that this task requires that tests have first been run, but this must be done separately. It will fail if it does not find the files generated during the execution of the tests that are necessary to produce the reports.
Downloads all the JAR dependencies declared in config.xml
, and required
to correctly build the project. The JAR files are extracted and placed in
the dep
or the lib
folder. When compiling (with the compile
task), the
compiler is instructed to include these JARs in its classpath. Depending on the
setting specified in config.xml
, these JARs are also bundled in the
output JAR file of the jar
task.
Deletes test reports only.
Deletes compiled files and test reports. The standard task to force a fresh recompilation of the sources.
Like clean
, but also deletes all JAR dependencies.
AntRun makes it easy to use continuous integration services like Travis CI or Semaphore. The sequence of commands to automatically setup the environment, build and test it is (for Linux):
$ ant
$ ant test
Notice how all the process is platform-independent.
Among other configuration settings, dependencies can be declared in the file
config.xml
. Locate the <dependencies>
section in that file, and add as
many <dependency>
entries as required. The structure of such a section is as
follows:
<dependency>
<name>Test Dep</name>
<classname>ca.uqac.lif.NonExistentClass</classname>
<files>
<jar>http://sylvainhalle.github.io/AntRun/placeholders/dummy-jar.jar</jar>
<zip>http://sylvainhalle.github.io/AntRun/placeholders/dummy-zip.zip</zip>
<tgz>http://sylvainhalle.github.io/AntRun/placeholders/dummy-tar.tgz</tgz>
</files>
<bundle>true</bundle>
</dependency>
The parameters are:
name
: a human-readable name for the dependency, only used for displayclassname
: a fully qualified class name that is supposed to be provided by the dependency. AntRun checks if this class name is present in the classpath; if not, it will download the files specified in thefiles
sectionfiles
: a list of eitherjar
,zip
ortgz
elements, each containing a URL to a JAR file, or an archive of JAR files. AntRun downloads these files and places them in either thedep
or thelib
folders of the project (both are in the classpath). If the URL is a zip or tgz, it also unzips the content of the archive.bundle
: when this element has the valuetrue
, the dependency is copied to thedep
folder; otherwise, it is copied to thelib
folder. As was said, both are in the classpath, but only the JARs in thedep
folder are bundled when creating a JAR file for the project (using thejar
task).
The .class
files are marked with the major version number of the compiler
that created them; hence a file compiled with JDK 1.11 will contain this
version number in its metadata. A JRE 1.8 will refuse to run them,
regardless of whether they were built from 1.8-compliant code.
Cross-compiling is necessary if one wants to make a project compatible
with a version of Java earlier than the one used to compile it.
By default, AntRun compiles your project using the default JDK installed on
your computer. However, you can compile files that are compatible with
a specific version of Java by setting the targetjdk
parameter to the
a version of Java (e.g. 8 for Java 8) in config.xml
.
Virtually every Java project developed at LIF uses an AntRun template project. This includes:
- Azrael, a generic serialization library
- BeepBeep 3, an event stream processing engine, and most of its palettes
- Bullwinkle, a runtime BNF parser
- Jerrydog, a lightweight web server
- LabPal, a framework for running computer experiments
- Petit Poucet, a generic explainability library
- Synthia, a modular data structure generator
- TeXtidote, a spelling and grammar checker for LaTeX documents
...and many more.
AntRun was written by Sylvain Hallé, Full Professor at Université du Québec à Chicoutimi, Canada.