When I run ant test
everything is cool, but when Travis runs the same command I get
$ ant test
Buildfile: /home/travis/build/AwesomeTeamPlayer/event-receiver/build.xml
compile:
[mkdir] Created dir: /home/travis/build/AwesomeTeamPlayer/event-receiver/build [javac] /home/travis/build/AwesomeTeamPlayer/event-receiver/build.xml:28:
warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 12 source files to /home/travis/build/AwesomeTeamPlayer/event-receiver/build [javac] Note: /home/travis/build/AwesomeTeamPlayer/event-receiver/src/EventReceiver/EventsCollection.java uses unchecked or unsafe operations. [javac] Note: Recompile with -Xlint:unchecked for details.
test-compile:
[mkdir] Created dir: /home/travis/build/AwesomeTeamPlayer/event-receiver/build/test [javac] Compiling 3 source files to /home/travis/build/AwesomeTeamPlayer/event-receiver/build/test
test:
BUILD FAILED
/home/travis/build/AwesomeTeamPlayer/event-receiver/build.xml:42:
Problem: failed to create task or type junit
Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
This looks like one of Ant's optional components. Action: Check that the appropriate optional JAR exists in -/usr/share/ant/lib -/home/travis/.ant/lib -a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
When I changed ant test
to ant test -lib ./lib/junit-4.12.jar
in .travis.yml file I get the same error message :/
.travis.yml:
language: java
jdk:
- oraclejdk8
services:
- docker
script: ant test -lib ./lib/junit-4.12.jar
build.xml:
<?xml version="1.0" encoding="iso-8859-2"?>
<project name="Project name" basedir="." default="compile">
<property name="src.dir" value="./src"/>
<property name="build.dir" value="./build"/>
<property name="lib.dir" value="./lib"/>
<property name="test.dir" value="./tests"/>
<property name="test.build.dir" value="./build/test"/>
<path id="classpath.compile">
<pathelement location="${lib.dir}/amqp-client-4.0.2.jar"/>
<pathelement location="${lib.dir}/json-20170516.jar"/>
<pathelement location="${lib.dir}/slf4j-api-1.7.25.jar"/>
<pathelement location="${lib.dir}/slf4j-simple-1.7.25.jar"/>
<pathelement location="${build.dir}"/>
</path>
<path id="classpath.test">
<pathelement location="${lib.dir}/mockito-all-1.10.19.jar"/>
<pathelement location="${lib.dir}/junit-4.12.jar"/>
<pathelement location="${lib.dir}/hamcrest-core-1.3.jar"/>
<pathelement location="${build.dir}"/>
</path>
<target name="compile" depends="">
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="classpath.compile"/>
</javac>
</target>
<target name="test-compile" depends="compile">
<mkdir dir="${test.build.dir}"/>
<javac srcdir="${test.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>
<classpath refid="classpath.compile"/>
</javac>
</target>
<target name="test" depends="test-compile">
<junit printsummary="on" haltonfailure="yes" fork="true">
<classpath>
<path refid="classpath.test"/>
<path refid="classpath.compile"/>
<pathelement location="${test.build.dir}"/>
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.dir}" includes="**/*Test.java" />
</batchtest>
</junit>
</target>
<target name="test-integration" depends="test-compile">
<junit printsummary="on" haltonfailure="yes" fork="true">
<classpath>
<path refid="classpath.test"/>
<path refid="classpath.compile"/>
<pathelement location="${test.build.dir}"/>
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.dir}" includes="integration/**/*Test.java" />
</batchtest>
</junit>
</target>
</project>
In lib dir I have
- amqp-client-4.0.2.jar
- hamcrest-core-1.3.jar
- json-20170516.jar
- junit-4.12.jar
- mockito-all-1.10.19.jar
- slf4j-api-1.7.25.jar
- slf4j-simple-1.7.25.jar