2012-11-03 47 views
2

我有一個現有的Maven項目,我試圖移植到gradle。在gradle中使用fmpp生成java文件

一個子模塊使用fmpp/freemarker生成大量的java文件,然後將它們反饋到構建中。

我是新來的gradle,想知道如果有人知道一個簡單的方法來做到這一點。

任何幫助,將不勝感激。

我目前的pom.xml看起來是這樣的:

<build> 
    <plugins> 
     <!-- Freemarker maven plugin for code generation --> 
     <plugin> 
      <groupId>com.googlecode.fmpp-maven-plugin</groupId> 
      <artifactId>fmpp-maven-plugin</artifactId> 
      <version>1.0</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.unix4j</groupId> 
        <artifactId>unix4j-tools</artifactId> 
        <version>0.1-SNAPSHOT</version> 
        <optional>true</optional> 
       </dependency> 
      </dependencies> 
      <configuration> 
       <cfgFile>src/main/resources/codegen/config.fmpp</cfgFile> 
       <outputDirectory>target/generated-sources/main/java</outputDirectory> 
       <templateDirectory>src/main/resources/codegen/templates</templateDirectory> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>src/main/generated</source> 
         </sources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

回答

3

對不起,應該花更多的時間使用Google首次。這是爲我工作的解決方案:

project(':unix4j-core:unix4j-command') { 
    configurations {pmd} 

    dependencies { 
     compile project(':unix4j-core:unix4j-base') 
     compile project(':unix4j-tools') 
     pmd project(':unix4j-tools') 
    } 

    task generateFmppSources(dependsOn: ":unix4j-tools:compileJava") << { 
     println "Generating sources...." 
     ant.taskdef(name:'fmpp', classname:'fmpp.tools.AntTask', classpath:configurations.pmd.asPath); 
     ant.fmpp configuration:"src/main/resources/codegen/config.fmpp", sourceRoot:"src/main/resources/codegen/templates", outputRoot:"target/generated-sources/main/java"; 
    } 
    compileJava.dependsOn generateFmppSources 
    sourceSets { 
     main { 
      java { 
       srcDir 'target/generated-sources/main/java' 
      } 
     } 
    } 
}