【问题标题】:Maven plugin development: is there a way to automatically run plugin when it's just declared in pom.xml?Maven 插件开发:有没有办法在 pom.xml 中声明时自动运行插件?
【发布时间】:2011-11-11 23:56:42
【问题描述】:

我正在开发一种新的魔力。它只有一个目标,因此不强制用户添加executions 部分(如果他们不想更改默认的phase)似乎是合乎逻辑的。

这应该是可能的,因为当我添加一个surefire 插件的非常简单的描述时,maven 明白它的单一目标test 应该运行,即:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4.3</version>
 </plugin>

这足以运行插件。

我怎样才能为我的插件实现类似的小配置?

这是我现在拥有的(如果没有executions 部分,它就无法工作):

/**
 *
 * @goal test
 * @phase test
 */
public class MyMojoPlugin extends AbstractMojo {

   ... (implementation details)    
}

<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>org.somegroup</groupId>
    <artifactId>mymojo-maven-plugin</artifactId>
    <packaging>maven-plugin</packaging>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>

        .... (other dependencies)

    </dependencies>

    <build>
        <plugins>
            ... (some plugins)
        </plugins>
    </build>

</project>

【问题讨论】:

    标签: java maven-2 maven maven-plugin


    【解决方案1】:

    “默认”生命周期绑定在 Maven 中定义。这在Build Lifecycle 文档中有描述,该文档还指出插件需要“执行”部分。

    我想您可以编辑 components.xml 并为您的特定站点重新编译 Maven。

    在我看来,至少对于内部开发而言,更好的选择是使用包含特定于站点的配置的共享父 POM。

    编辑:我正在寻找对父 POM 的引用,并看到了 this。我不确定这是否是 Maven3 独有的功能,但可能值得研究。

    【讨论】:

      猜你喜欢
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2022-01-17
      • 2014-07-27
      • 1970-01-01
      相关资源
      最近更新 更多