0

I was migrating a java project in ant-build to gradle build. I am stuck with source code.

I have already done this in another project with WSDL conversion to java successfully. But in this case I am not aware.

Ant code is here

<taskdef name="codegen" classname="com.company.container.ant.GeneratorTask" 
         classpathref="codegen.path" loaderref="classes"/>
<codegen toDir="${dir.generated}" metaDestDir="${dir.compile}" 
         configFile="${dir.compile}/container/local_services.xml">
<fileset dir=".">
    <include name="src/java/com/**/container/*Impl.java"/>
</fileset>
</codegen>
<echo message="Generate biz service interfaces complete."/>
        </target>
<target name="compile.codegen" description="Compile generated code.">
<javac srcdir="${dir.generated}" destdir="${dir.compile}" 
       deprecation="${build.deprecation}" debug="${build.debug}">
    <classpath>
        <path refid="classpath.build"/>
    </classpath>
</javac>
<echo message="Done compiling generated code."/>
</target>

Do anyone has any idea ?

smilyface
  • 5,021
  • 8
  • 41
  • 57
  • 3
    Please try to be more specific. What part do you not understand exactly? What exactly have you tried so far? – reto Sep 24 '15 at 13:20
  • How to convert this to gradle ? I even actually didn't understand how this works ! This code (in ant) generates new java files. – smilyface Sep 25 '15 at 04:49
  • It seems to use some custom code generator, unlike WSDL generator. So, you have to provide the behaviour and input/output for it, or? as temporary solution, just import this ant task into gradle build script. – Stanislav Sep 25 '15 at 08:55

1 Answers1

0

Yep ! I have done it. This works.

task generateTheSourceFiles {
    doLast {
        generatedSrcDir.exists() || generatedSrcDir.mkdirs()
        ant.taskdef(name: 'generateJavaCode', classname: 'com.company.container.ant.GeneratorTask', classpath: configurations.generateJavaCode.asPath, loaderref: 'classes')
        ant.taskdef(name: 'attributeCompiler', classname: 'org.apache.commons.attributes.compiler.AttributeCompiler',
                classpath: configurations.attributeCompiler.asPath, loaderref: 'classes')
        ant.generateJavaCode(toDir: generatedSrcDir, metaDestDir: 'build/classes', configFile: 'src/main/resources/container/local_services.xml') {
            fileset(dir: 'src/main/java', includes: 'com/**/container/**/*Impl.java', excludes: 'com/company/web/container/*Impl.java')
        }
        ant.attributeCompiler(destDir: generatedSrcDir) {
            fileset(dir: 'src/main/java', includes: 'com/**/container/**/*.java')
        }
    }
}
smilyface
  • 5,021
  • 8
  • 41
  • 57