5

在我的 pom.xml 中,我配置了一个插件来将某些 Protobuf 文件转换为 Java 类文件。它看起来像这样:

<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 以包含自定义条目的一般问题,因为我们有更多的地方想要添加自定义的东西。

4

3 回答 3

2

登录并为此功能请求投票:

已经有补丁了,改进一下。

于 2014-01-21T15:02:51.337 回答
0

您示例中的 Eclipse 配置是由m2eclipse的项目配置生成的,我很确定它现在不支持此类功能。尽管您可以尝试提交增强请求。见http://www.eclipse.org/m2e/support/

于 2014-01-15T21:18:14.937 回答
0

不确定是否可以使用maven。您将不得不从 maven 调用 ant 插件。添加自定义逻辑以在 Ant 任务中添加额外的行。

在您的插件下方添加 ant 插件,以确保在您的插件之后在同一阶段调用 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>
于 2014-01-16T10:33:40.463 回答