Following the example given at http://www.jooq.org/doc/2.4/manual/META/Configuration/#N10607 on how to run the jooq code-generation I ran into the problem that the build fails with the message:
codegen.xml:7: taskdef class org.jooq.util.GenerationTask cannot be found
For a reference, here is codegen.xml
<project name="..." default="generate-test-classes"
basedir=".">
<property name="path.to.jooq.distribution" value="${basedir}/libs"/>
<property name="path.to.mysql.driver" value="${basedir}/libs"/>
<property name="mysql.driver" value="mysqlcon"/>
<!-- Task definition -->
<taskdef name="generate-classes" classname="org.jooq.util.GenerationTask">
<classpath>
<fileset dir="${path.to.jooq.distribution}">
<include name="jooq.jar" />
<include name="jooqmeta.jar" />
<include name="jooqcodegen.jar" />
</fileset>
<fileset dir="${path.to.mysql.driver}">
<include name="${mysql.driver}.jar" />
</fileset>
</classpath>
</taskdef>
<!-- Run the code generation task -->
<target name="generate-test-classes">
<generate-classes jdbcurl="jdbc:mysql://localhost:3306/crawler"
jdbcuser="..." jdbcpassword="..." generatordatabaseinputschema="..."
generatortargetpackage="model.persistence.jooq"
generatortargetdirectory="${basedir}/src" />
</target>
</project>
I triple checked the definition of the classpath and every file listed exists under the given location. So what would be the problem? Am I missing something? Do I need to configure ant somewhere to recognize the task?
Since I already checked ant: failed to create task or type, I tried to move the taskdef inside the target, but to no avail.
The ant task was an example implementation in jOOQ 2.x. It has been deprecated a long time ago and removed from jOOQ 3.0:
http://www.jooq.org/notes.php?version=3.0
https://github.com/jOOQ/jOOQ/issues/1118
http://www.jooq.org/doc/3.1/manual/code-generation/codegen-configuration/#N12E23
The version of the manual that you've linked is quite outdated.
Related
I am trying to migrate my test suite from Junit4 to Junit5. Have a bunch of System Properties given as parameters in the older targets which run tests on Junit4 but now as i am migrating to Junit5, JunitLauncher doesn't support this parameter .
Older Target which runs tests on Junit4:
<target name="test">
<mkdir dir="${junit_reports.dir}" />
<junit printsummary="${junit.printsummary}" haltonfailure="${junit.haltonfailure}" haltonerror="${junit.haltonerror}" showoutput="${junit.showoutput}" fork="true" forkmode="once" failureProperty="failed">
<sysproperty key="clover.initstring" value="${clover.dbdir}/${clover.dbfile}" />
<sysproperty key="rules.location" value="${classes.dir}/rules/impl" />
<classpath>
<path refid="classes.classpath" />
<path refid="test.classpath" />
<pathelement path="${basedir}/../../.." />
<pathelement path="${test.classes.dir}" />
<path location="${basedir}/../common/target/test_classes" />
<pathelement location="${3rdparty.dir}/prime-server-framework/framework-core-mock.jar" />
</classpath>
<formatter type="${unittest.output.type}" />
<batchtest fork="true" todir="${junit_reports.dir}">
<fileset dir="${test.classes.dir}" includes="${tests.patternset}" />
</batchtest>
</junit>
</target>
New Target which runs tests on Junit5:
<target name = "sampletest">
<mkdir dir="${junit_reports.dir}" />
<junitlauncher>
<classpath>
<path refid="classes.classpath" />
<path refid="test.classpath" />
<pathelement path="${basedir}/../../.." />
<pathelement path="${test.classes.dir}" />
<path location="${basedir}/../common/target/test_classes" />
</classpath>
<!--<testclasses outputdir="${junit_reports.dir}">
<fileset dir="${test.classes.dir}">
<include name = "**/*Test.class"/>
</fileset>
</testclasses>-->
<test name = "impl.RulesEngineValidationTest"/>
</junitlauncher>
</target>
How do i give system properties in new target?
Ant 1.10.4 does support JUnit 5. However, it does not support all the features that Ant integration JUnit 4 does. In particular, it does not support forking the junit process and therefore passing system properties.
I found this question because I was trying to do the same thing. I found a workaround though. You can set the system properties in code before calling junitlauncher.
This code is what I used to set a single system property for file encoding. You could do something similar for your properties.
<script language="javascript">
<![CDATA[
var imports = new JavaImporter(java.lang.System);
imports.System.setProperty('file.encoding', 'ISO8859_1')
]]>
</script>
Yours is a little more complicated since your properties use others. You can read an Ant variable from inside the code. (I don't know how to read one with a dot in the name so I got rid of the dot in this example)
<property name="cloverdbdir" value="clover-dir-property-value" />
<property name="cloverdbfile" value="clover-db-file-property-value" />
<script language="javascript">
<![CDATA[
var imports = new JavaImporter(java.lang.System);
imports.System.setProperty('clover.initstring', cloverdbdir + '/' + cloverdbfile);
print(imports.System.getProperty('clover.initstring'));
]]>
</script>
There are a few things to be aware of if you use this technique:
Nashorn is deprecated for removal. It is definitely in Java 11. However, it isn't guaranteed to all future versions. It seems likely that Ant will add the system property functionality natively by then so I'm not worried about it.
The system property remains set for the remainder of the build. This doesn't look like a problem for you. If it is, you'd need another script block after calling JUnit to null it out.
<path id="checkstyle.classpath">
<fileset dir="${basedir}/lib/">
<include name="checkstyle-6.12.1-all.jar" />
</fileset>
</path>
<target name="checkstyle">
<!-- CheckStyle -->
<taskdef resource="checkstyle.properties" classpath="C:\Users\Pil\Desktop\Workspace2\Cs376bDemoApp\lib
\checkstyle-6.12.1-all.jar" />
<checkstyle config="DsrJavaFormattingProfile.xml" classpath="C:\Users\Pil\Desktop\Workspace2\Cs376bDemoApp\lib
\checkstyle-6.12.1-all.jar" />
<fileset dir="${src}" includes="**/*.java" />
</target>
This is my checkstyle target in my build.xml file. I have spent the past 6 hours debugging this before resorting to StackOverFlow but my best efforts proved fruitless. I am consistently met with the error report [taskdef] Could not load definitions from resource checkstyle.properties. It could not be found.
BUILD FAILED
C:\Users\Pil\Desktop\Workspace2\Cs376bDemoApp\build.xml:86:
Problem: failed to create task or type checkstyle
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
My intention for this code is for it to use my DsrJavaFormattingProfile.xml on the .java files in my src directory. I have tried replacing the class path with the relative path "lib/" and with the checkstyle.classpath path above aswell as every possible other solution I could think of.
<taskdef resource="checkstyle.properties" classpathref="checkstyle.classpath" />
<checkstyle config="DsrJavaFormattingProfile.xml" classpathref="checkstyle.classpath" />
also resulted in the same error. Please save me StackOverFlow, I need a hero.
https://www.youtube.com/watch?v=OBwS66EBUcY
Update: Solved by CAustin
`
<target name="checkinit">
<path id="checkstyle.lib.path">
<fileset dir="lib" includes="checkstyle8.8all.jar" />
</path>
<taskdef resource="com/puppycrawl/
tools/checkstyle/ant/checkstyle-ant-task.properties" classpathref="checkstyle.classpath" />
</target>
<target name="checkstyle" depends="checkinit">
<!-- CheckStyle -->
<checkstyle config="${basedir}\DsrCheckStyleConfig.xml" classpathref="checkstyle.lib.path">
<path refid="project.sourcepath" />
</checkstyle>
</target>`
I'm currently playing with Ant to do some auto branding work. I modified default build.xml and setup my own target. What I hope to ask is that is there a way in Ant Script that could automatic renaming the apk file just build with the certain name?
I currently has this Ant target setup in my build.xml:
<target name="release-brandA"
depends="default, -set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode for brandA.">
<delete dir="${res}" />
<copydir dest="${res}" src="${branding}/brandA" forceoverwrite="ture" />
<replaceregexp flags="g" byline="false">
<regexp pattern="import com.arthur.android(.*).R;"/>
<substitution expression="import com.arthur.android.brandA.R;"/>
<fileset dir="src" includes="**/*.java" />
</replaceregexp>
<replaceregexp flags="g" byline="false">
<regexp pattern="package="com.arthur.android(.*)"" />
<substitution expression="package="com.arthur.android.brandA"" />
<fileset dir="" includes="AndroidManifest.xml" />
</replaceregexp>
</target>
Is there a way that I could add some more task, to let the output file just be like brandA.apk?
Thank you!
The final apk filename is actually defined by the property 'out.final.file'
So you could create a new Task that sets this property:
<target name="-set-out-final-file">
<property name="out.final.file" location="${out.absolute.dir}/brandA.apk" />
</target>
Finally, you just need to invoke the -set-out-final-file target before calling the debug or release targets.
Using your release-brandA task, it would become this:
<target name="release-brandA"
depends="default, -set-out-final-file, -set-release-mode, -release-obfuscation-check...
Here I found more better explanation and more suitable way to override release target.
Please refer to section:
<target
name="release"
depends="custom-set-release-mode, android_rules.release" />
Its very simple.Refer this link [1]: https://ant.apache.org/manual/running.html
So in the above case,we need to run it like this,
ant debug -Dout.final.file=brandA.apk
Thats it.
I am trying to use CRAP4J utility to analyse my code and I am stuck while passing the classpath. My ant task look like as follows;
<target name="run-crap-4j" unless="crap-4j-finishes" depends="init" description="This target will run crap-4j for analysis." >
<crap4j projectdir="${basedir}" outputDir="${build.dir}${file.separator}reports${file.separator}crap4j"
dontTest="false" debug="false">
<srces>
<pathElement location="${base.dir}${file.separator}src" />
</srces>
<classes>
<pathElement location="${build.dir}${file.separator}classes" />
</classes>
<testClasses>
<pathElement location="${build.dir}${file.separator}testclasses" />
</testClasses>
<libClasspath>
<path refid="${project.classpath}" />
<path refid="${test.classpath}" />
</libClasspath>
</crap4j>
<property name="crap-4j-finishes" value="true"/>
</target>
When I run my target it gives me following error;
run-crap-4j:
Unresolvable reference ${project.classpath} might be a misuse of property expansion syntax.
BUILD FAILED
C:\RTC\TechDev\SoaFramework\build.xml:931: Reference ${project.classpath} not found.
According to CRAP4J documentation in I should be passing the fileset but the problem is that I do not have my dependencies at one location, they are scattered all over. Could you please help me sort this problem or give me suggestion on how to proceed now?
Thanks
--
Sjunejo
Apparently its a bug in CRAP4J. Refer following link for solution;
http://code.google.com/p/crap4j/issues/detail?id=12
Thanks,
--
SJunejo
I tried to get Cobertura running inside my ant script, but I'm stuck right at the beginning. When I try to insert the cobertura taskdef I'm missing the Log4J libraries.
Ant properties & classpath
<property name="cobertura.dir" location="/full/path/to/cobertura-1.9.3" />
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
My ant target
<!-- =================================
target: cobertura
================================= -->
<target name="cobertura" depends="clean, init" description="Generates cobertura coverage reports">
<cobertura-instrument todir="${dir.build.instrumented}">
<fileset dir="${dir.build}">
<include name="**/*.class" />
</fileset>
</cobertura-instrument>
</target>
I think I did everything like it is described in the Cobertura documentation but I get this
Ant build error
BUILD FAILED
build.xml:95: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
Inside the ${cobertura.dir} there is the lib directory with all files. I unzipped it from the cobertura distribution ZIP directly into that directory.
Am I missing a step? Something wrong with my configuration so far?
I also encountered this problem today and solved it by specifying the location of all the required libraries as part of the class path provided to my taskDef task.
<path id="cobertura.class.path">
<pathelement location="${common.dir}/../tools/cobertura/cobertura.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/asm-3.0.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/asm-tree-3.0.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/log4j-1.2.9.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/jakarta-oro-2.0.8.jar" />
</path>
<taskdef classpathref="cobertura.class.path" resource="tasks.properties" />
Go to your ant/lib dir and make sure there is NO file cobertura.jar there. If it's there - remove it and try again.
Change this
<include name="lib/**/*.jar" />
to
<include name="*.jar" />
Hope this helps!
I just upgraded to the latest cobertura and mine works fine. Is it possible that something else is on the CLASSPATH with a different version of log4j so it is picking up wrong one?
Make sure that classpath used in taskdef and cobertura-instrument are the same. This helped me with the same issue.
I too faced this problem, I just added all jars given with cobertura in the classpath to resolve this issue