2013-10-16 25 views
5

在我的pom.xml中,我配置了一個插件來將某些Protobuf文件轉換爲Java類文件。它看起來像這樣:如何將特定配置添加到Maven插件

<plugin> 
     <groupId>com.github.igor-petruk.protobuf</groupId> 
     <artifactId>protobuf-maven-plugin</artifactId> 
     <version>0.5.3-SNAPSHOT</version> 
     <executions> 
       <execution> 
         <goals> 
           <goal>run</goal> 
         </goals> 
       </execution> 
     </executions> 
     <configuration> 
       <protocCommand>${basedir}/protoc/bin/protoc</protocCommand> 
       <inputDirectories> 
        <inputDirectory>proto</inputDirectory> 
       </inputDirectories> 
     </configuration> 
</plugin> 

出於這種的Maven生成.classpath文件,輸入以下內容:

<classpathentry kind="src" output="target/classes" path="target/generated-sources/protobuf"> 
    <attributes> 
     <attribute name="optional" value="true"/> 
     <attribute name="maven.pomderived" value="true"/> 
    </attributes> 
</classpathentry> 

我現在想的Maven做的是一個額外的「屬性」項添加到該類路徑條目,以便該條目看起來像這樣:

<classpathentry kind="src" output="target/classes" path="target/generated-sources/protobuf"> 
    <attributes> 
     <attribute name="optional" value="true"/> 
     <attribute name="maven.pomderived" value="true"/> 
     <attribute name="ignore_optional_problems" value="true"/> 
    </attributes> 
</classpathentry> 

像這樣,我不會從該代碼部分得到警告。

目前我只是不知道該怎麼做。我必須編輯哪些文件或其他設置?在Eclipse中我可以做到這一點?
但是這或多或少是一個普遍性的問題作爲Maven可以如何被修改爲包括定製的項目,因爲我們有一些更多的斑點,我們將要添加自定義的東西英寸

在你的榜樣

回答

0

不知道是否有可能使用maven。你將不得不從maven中調用ant插件。添加自定義邏輯以在Ant任務中添加額外的行。

在插件下面添加螞蟻插件,以確保螞蟻插件在同一階段插件後被調用。確保螞蟻插件與您的插件具有相同的階段。

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
     <execution> 
     <phase><!--the same phase as protobuf-maven-plugin phase--></phase> 
     <configuration> 
      <tasks> 

      <!-- 
       Add ant xmltask or ant other task to add your line to file 
      --> 

      </tasks> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
+0

我肯定不會混用Ant和Maven。 – Sebastian

+0

那麼在這種情況下,我會建議創建自己的自定義maven插件。請參考創建Maven插件的鏈接。 http://maven.apache.org/guides/plugin/guide-java-plugin-development.html – ABose