Enterprise Java

Apache Ant 1.10.6 released – fork mode for junitlauncher and new jmod and link tasks

Apache Ant 1.10.6 has been released this week. This release contains numerous bug fixes as well as some very exciting new features. The complete release notes is available here and the downloads itself are available here. In this article, I will go over some of the new features that have made it into this release.

Running JUnit5 tests in a forked JVM, using junitlauncher task

A while back, Ant 1.10.x introduced support for JUnit5 tests to be launched using the new “junitlauncher” task. Given the nature of changes between JUnit 4.x and JUnit 5, the amount of support introduced in the new “junitlauncher” task was minimal. Based on user feedback about this task, this task has now been enhanced to support “fork” mode. This was one of the most asked for enhancement, in this task. The “fork” mode support in this task now allows users to configure this task to launch the tests in a forked JVM instead of running these tests within the same JVM as the one, the build is currently running in. Fork mode allows much more control over how these tests execute (things like setting up additional JVM arguments just for these tests or even system properties). The complete details of how to use fork mode in this task, is available in the manual for this task. Here’s a very basic minimal example of one such usage:

<target name="test-basic-fork">
        <junitlauncher>
         <!-- Imagine test.classpath points to a previously configured path -->
            <classpath refid="test.classpath"/>
            <test name="org.example.myapp.SampleTest" outputdir="${output.dir}">
                <fork dir="${basedir}">
                    <sysproperty key="myapp-system-property" value="hello world!"/>
                </fork>
            </test>
        </junitlauncher>
</target>

The example above, sets up “junitlauncher” task to launch a test class named “org.example.myapp.SampleTest” in a forked JVM. The “fork” element in the example above is configured to setup a Java system property named “myapp-system-property” with a value of “hello world!”. When the test executes, this Java system property will be made available to this test or any other class being executed in that forked JVM. More advanced ability of the “fork” element is explained in the manual linked previously.

New jmod and link tasks for Java 9+ tools

Java 9 shipped with a new modular ecosystem. This also brought in new tools to create and manage the Java modules. In this release of Ant 1.10.6, we introduce new tasks – “jmod” and “link”, which can be used to create Java modules and then assemble them to create custom JVM runtime images. More details about these tasks can be found in their manuals
here and here. A big thanks to Craig Pell who contributed these valuable tasks. More Java 9+ enhancements are being worked upon in Ant and we plan to make them available in future releases.

Please do download this new version of Ant and provide us feedback, suggestions in our user mailing list.

Published on Java Code Geeks with permission by Jaikiran Pai, partner at our JCG program. See the original article here: Apache Ant 1.10.6 released – fork mode for junitlauncher and new jmod and link tasks

Opinions expressed by Java Code Geeks contributors are their own.

Jaikiran Pai

Jaikiran works for Red Hat and is a developer in the JBoss application server development team. He's one of the authors of "JBoss AS Getting Started" DZone RefCard. When he's not doing anything JBoss related, you can usually find him at JavaRanch, in his role as a Sheriff(Moderator). He blogs at jaitechwriteups
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button