Hi all,

I solved the problem by circumventing the ant builder
and wrapping that code within the main method of a class
in buildSrc, which ich excecute via JavaExec with the
appropriate classpath.

The solution with more detail is attached at the end.

One question is open:
It should be enough to write the class directly in the build.gradle file.
But I couldn't figure out what package to use for the main class.
How can I execute a class defined inline in the build script?

Best regards
Thomas

The solution with more detail:

The new reverse engineering task:
---------------------------------
task hibernateToolTask(type: JavaExec, dependsOn: sqlTask){
 main = 'utils.ReverseEngineeringExecutor'
 classpath = configurations.hibernateGenTask
 args "$dirGeneratedResources/db.properties",
             'mapper.dao',
      'src/main/resources/build/hibernate.reveng.xml',
      'utils.ExtendDelegatingReverseEngineeringStrategy',
      dirGeneratedHbmRaw, dirGeneratedJava, dirGeneratedResources
 systemProperty 'log4j.configuration', 'build_log4j.xml'
}
compileJava.dependsOn(hibernateToolTask)
The class in buildSrc:
----------------------
import groovy.sql.Sql
import org.apache.tools.ant.Project
import org.apache.tools.ant.types.Path
import org.hibernate.tool.ant.ExporterTask
import org.hibernate.tool.ant.HibernateToolTask
import org.hibernate.tool.ant.JDBCConfigurationTask
import org.hibernate.tool.hbm2x.Exporter
import org.hibernate.tool.ant.Hbm2JavaExporterTask;
import org.apache.log4j.Logger
class ReverseEngineeringExecutor {
  private static Logger log =
Logger.getLogger(ReverseEngineeringExecutor.class)

  public static void main(String[] args) {
 def propertyfile = args[0]
 def packagename = args[1]
 def revengfile = args[2]
 def reversestrategy = args[3]
 def dirGeneratedHbmRaw = args[4]
 def dirGeneratedJava = args[5]
 def dirGeneratedResources = args[6]

 log.info("Reverse Engineering DB")
 HibernateToolTask htt = new HibernateToolTask();
 JDBCConfigurationTask task = htt.createJDBCConfiguration();
 task.setPropertyFile(new File(propertyfile));
 task.setRevEngFile(new Path(new Project(), revengfile));
 task.setPackageName(packagename);
 task.setReverseStrategy(reversestrategy);

 log.info("Generate XML Mappings")
 ExporterTask xmlTask = htt.createHbm2HbmXml();
 xmlTask.setDestdir(new File(dirGeneratedHbmRaw));
 xmlTask.execute();

 log.info("Generate Java classes")
 Hbm2JavaExporterTask javaTask = (Hbm2JavaExporterTask)htt.createHbm2Java();
 javaTask.setJdk5(true); //we want generics
 javaTask.setDestdir(new File(dirGeneratedJava));
 javaTask.execute();

 log.info("Generate hibernate cfg")
 ExporterTask cfgTask = htt.createHbm2CfgXml();
 cfgTask.setDestdir(new File(dirGeneratedResources));
 cfgTask.execute();
  }
}

Reply via email to