【问题标题】:Maven default compile not picking up custom plugin goalMaven默认编译没有选择自定义插件目标
【发布时间】:2014-03-30 16:48:11
【问题描述】:

我写了一个自定义插件,然后我安装了它。然后我修改了我想使用自定义插件的项目的pom.xml。当我直接调用我的插件目标时,插件目标成功执行,但是当我尝试mvn compile 时,我的自定义插件目标没有执行。可能是什么原因?

我的插件pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xxx.plugins.maven</groupId>
  <artifactId>datanucleus-enhance-maven-plugin</artifactId>
  <packaging>maven-plugin</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>Datanucleus-enhance Maven Plugin</name>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我使用自定义插件的项目我添加了以下内容:

    <!-- enhance JDO classes -->
    <plugin>
      <groupId>com.sukantu.plugins.maven</groupId>
      <artifactId>datanucleus-enhance-maven-plugin</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <configuration>
        <jdoClassDirList>
          <param>target/${project.artifactId}-${project.version}/WEB-INF/classes/</param>
        </jdoClassDirList>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>enhance</goal>
            </goals>
          </execution>
        </executions>
    </plugin>

我遵循了 maven 指南站点中的 将 Mojo 附加到构建生命周期部分:https://maven.apache.org/guides/plugin/guide-java-plugin-development.html

以下命令成功调用了我的插件目标: mvn com.xxx.plugins.maven:datanucleus-enhance-maven-plugin:enhance

以下命令未成功调用我的插件目标: mvn compile

感谢您的任何意见!

【问题讨论】:

  • 你在哪里定义的插件配置? //?
  • 我之前尝试使用 pluginManagement,但后来发现如何解决此问题。请参阅我发布的答案。谢谢。

标签: maven-plugin


【解决方案1】:

我看到了这个链接: How do I link a plugin execution to a phase in maven without forcing me to specify plugin on command line

所以我删除了&lt;pluginManagement&gt; 标签,所以&lt;plugins&gt; 直接出现在“&lt;build&gt;”下。然后我从命令行尝试了'mvn compile',它成功调用了我的自定义插件目标!

但是当我在 Eclipse 中检查 pom.xml 时,我看到这里引用了另一个错误 How to solve “Plugin execution not covered by lifecycle configuration”

由于命令行工作正常,我认为这是 m2e Eclipse 插件错误,所以我通过转到 'Eclipse' -> 'Window' -> 'Show View' -> 'Markers' -> 禁用了标记右键单击该标记 - >“删除”。现在 Eclipse 没有显示任何错误,命令行也按预期工作。希望这对其他人有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    相关资源
    最近更新 更多