How to place a custom code generator in a gradle script


(Patrick Reinhart) #1

I’m migrating our old build environment from ivy/ant over to Gradle. I was successful in converting the basic parts of the build, but now I need some help getting the next step done. After searching around I was not able to find a clear way to do this:

We use a custom code generator at the moment by calling an java class with some parameters something like this in ANT:

<java classname="CH.obj.persistence.generator.DatatypeGenerator" fork="true" failonerror="true">
  <jvmarg value="-server" />
  <jvmarg value="-Xmx2048m" />
  <jvmarg value="-DDB_SQL_SKINNAME=${ddi.DB_SQL_SKINNAME}" />
  <jvmarg value="-DDB_CONNECT_USER=${ddi.DB_CONNECT_USER}" />
  <jvmarg value="-DDB_CONNECT_PASSWORD=${ddi.DB_CONNECT_PASSWORD}" />
  <jvmarg value="-DDB_CONNECT_INFO=${ddi.DB_CONNECT_INFO}" />
  <classpath>
    <libs />
    <fileset dir="${bs.project.lib.dir}" />
  </classpath>
  <args />
  <arg value="@{target.dir}" />
</java>

Now I need some help to pack this into a custom task (I guess) and defining some additional sourceSet where the generated code will go. This should later also be in a separate artifact.

It would be great to get some hints on how to do that task…

-Patrick