Groovyc NoSuchMethodException - ant

I'm using Groovyc to compile a project in Ant. That's how i'm doing :
<path id="lib.path">
<fileset dir="${pathWhereIsTheJar&Others}">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="lib.path"/>
The thing is: Everytime i run the task i get the following Exception:
java.lang.NoSuchMethodError:
org.codehaus.groovy.tools.FileSystemCompiler.createCompilationOptions()Lgroovyjarjarcommonscli/Options;
I'm using the groovy-all-2.1.3.jar and according to grepCode this method exists on this version.
What could be the problem?

Related

Ant task is unable to recognize android private libraries

I am trying to run findbugs through ant. This is a snippet of a part of my build file:
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" >
<classpath>
<fileset dir="${findbugs.home}/lib" includes="**/*.jar"/>
<pathelement location="${project.target.android.jar}" />
</classpath>
</taskdef>
<path id="build.classpath">
<pathelement location="${project.target.android.jar}" />
<fileset dir="libs">
<include name="*.jar"/>
</fileset>
</path>
<target name="findbugs" >
<findbugs home="${findbugs.home}" output="html" outputFile="findbugs/findbugs.html">
<class location="${out.classes.absolute.dir}" />
<auxClasspath refId="build.classpath"/>
<sourcePath path="${source.absolute.dir}" />
</findbugs>
</target>
This is unable to recognize the android library and gives errors like: cannot find android.os.Bundle,
etc,...
How do I make it recognize android libraries? I have tried including it using , but this doesn't seem to work.
I am not aware of the complete build file, but the main project compilation works fine, and the android lib included there are in this format:
<gettarget
androidJarFileOut="project.target.android.jar"
...
Findbugs works on Java's class file format. Android uses another format called dex. So Findbugs will not work on that.

Can't run Groovy test cases from Ant

My Ant target looks like this:
<target name="junit" depends="compile">
<junit haltonfailure="true" printsummary="true">
<classpath>
<fileset dir="${idea.dir}/lib" includes="junit.jar" />
<fileset dir="${build.dir}" includes="**" />
</classpath>
<formatter type="plain" usefile="true" />
<batchtest fork="false" todir="${out.dir}">
<fileset dir="${build.dir}" includes="test_*/*Test.class" />
</batchtest>
</junit>
</target>
All compiled classes from the project are in ${build.dir}, as well as all compiled test cases. The latter are within ${build.dir}/test_* sub folders.
There is one test class ${build.dir}/test_ecs/EntityManagerTest.class, which apparently is found in batchtest. However, Ant gives me this output in the junit report:
test_ecs.EntityManagerTest
java.lang.ClassNotFoundException: test_ecs.EntityManagerTest
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
Now, what I don't understand is: Why is the test case class file found, but then the error says exactly that class is not found?
try modifying the <classpath>.. section like this:
<junit ..>
<classpath>
<pathelement location="${idea.dir}/lib/junit.jar"/>
<pathelement path="${build.dir}"/>
</classpath>
and see if it runs...
I suspect your issue is the classpath declaration:
<classpath>
<fileset dir="${idea.dir}/lib" includes="junit.jar" />
<fileset dir="${build.dir}" includes="**" />
</classpath>
Are your *.class files located in the build directory? Or a subdirectory of the build dir?
By way of example here's my standard junit task:
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="test.path"/>
<pathelement path="${build.dir}/classes"/>
<pathelement path="${build.dir}/test-classes"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${build.dir}/test-reports">
<fileset dir="${test.src.dir}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
Note the classpath declaration. It includes the path to 3rd party dependency jars, the directory where I compiled my classes to and the directory I compiled my test classes to.

How to run dbunit task in ant?

It doesn't work in ant,
I'd like to run some classes that extend DatabaseTestCase
<path id="libs.dir">
<fileset dir="lib" includes="**/*.jar" />
</path>
<taskdef name="dbunit"
classname="org.dbunit.ant.DbUnitTask"/>
<!-- run all tests in the source tree -->
<junit printsummary="yes" haltonfailure="yes">
<formatter type="xml"/>
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
It says the following:
Buildfile: D:\kariakin\jdbc_task\build.xml
BUILD FAILED
D:\kariakin\jdbc_task\build.xml:15: taskdef class org.dbunit.ant.DbUnitTask cannot be found
using the classloader AntClassLoader[]
I think the problem is your taskdef, it's missing the path containing the dbunit jar:
<taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask" classpathref="libs.dir"/>

Using Ant for S3 Uploading

I tried to implement the awstasks Class for uploading files via an ant script to an S3 bucket.
Downloaded all dependencies and used the following code:
<taskdef name="S3Upload" classname="dak.ant.taskdefs.S3Upload">
<classpath refid="classpath.compile"/>
</taskdef>
<target name="final2S3">
<basename property="customer.id" file="${basedir}"/>
<basename property="customer.name" file="${basedir.parent.parent}"/>
<basename property="customer.campaign" file="${basedir.parent}"/>
<basename property="customer.final" file="${basedir.parent}\_final\${customer.id}\"/>
<S3Upload verbose="true"
accessId="${aws.accessId}"
secretKey="${aws.secretKey}"
bucket="${aws.bucket}\${customer.id}"
publicRead="true">
<fileset dir="${customer.final}">
<include name="**/*.json"/>
<include name="**/*.swf"/>
</fileset>
</S3Upload>
</target>
I get the following error:
Reference classpath.compile not found.
I tried to set the property classpath.compile to the lib folder in the Ant home but nothing changes.

Java task cannot find classpath

I have a small program that displays some database tables. The program has a class with a main() method. I have an ant script that builds and runs the program.
The ant script is able to build the program and runs its tests but not run it. When i run it I get the following error:
[java] Could not find com.my.MyProgram. Make sure you have it in your classpath
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:138)
The issue here is that my java task target is not finding my classpath. I have printed my classpath and it has all the necessary jars and classes.
Here is part of my build.xml:
<path id="classpath">
<pathelement location="${build.src}" />
<pathelement location="${build.test}" />
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="run" depends="compile">
<java classname="MyProgram" fork="false">
<classpath refid="classpath"/>
</java>
</target>
Does anyone know why the run task cannot find my classpath?

Resources