2014-02-28 44 views
1

我想從我的maven文件中執行protoc(protobuffer編譯器)。我包埋在類似下面的如何在maven中從protoc生成多個類?

<executions> 
    <execution> 
     <id>generate-sources</id> 
     <phase>generate-sources</phase> 
     <configuration> 
     <tasks> 
      .... <!-- I have several of these blocks - how can I reduce them to one? --> 
      <exec executable="protoc/protoc.exe"> 
       <arg value="--java_out=target/generated-sources"/> 
       <arg value="src/main/protos/Proto1.proto"/> 
       <arg value="--proto_path=src/main/protos"/> 
      </exec> 
      <exec executable="protoc/protoc.exe"> 
       <arg value="--java_out=target/generated-sources"/> 
       <arg value="src/main/protos/Proto2.proto"/> 
       <arg value="--proto_path=src/main/protos"/> 
      </exec> 
     ..... 
     </tasks> 
     <sourceRoot>target/generated-sources</sourceRoot> 
    </configuration> 
    <goals> 
     <goal>run</goal> 
    </goals> 
    </execution> 

pom.xml中的Ant任務我怎麼能定義一個循環或東西,所以行家迭代遍佈在目錄中的文件?

我知道這裏有一個protobuffer maven插件,但我不得不聲明一個外部存儲庫來使用它,這目前不是一個選項。

+0

您的代碼看起來更像是一個Ant任務。如果是這樣,這是一個螞蟻問題。你可以看一下apply:http://ant.apache.org/manual/Tasks/apply.html –

+0

在Maven中目前不存在迭代文件的可能性。 – khmarbaise

+0

問題改寫 – morpheus05

回答

3

應用ant任務應該是你需要的。通過更換高管的名單:

<apply executable="protoc/protoc.exe" parallel="false"> 
    <arg value="--java_out=target/generated-sources"/> 
    <srcfile/> 
    <arg value="--proto_path=src/main/protos"/> 
    <fileset dir="${basedir}/src/main/protos" includes="*.proto"/> 
</apply> 

http://ant.apache.org/manual/Tasks/apply.html

+0

好吧,這個工程,但只有當你像這樣添加$ {base.dir}時:否則protoc會變得瘋狂。 – morpheus05

相關問題