Simple Maven Mojo Plug-in:布尔参数

时间:2010-11-22 17:51:04

标签: maven maven-plugin

这应该很简单 - 我想我只是忽略了一些东西。我有一个简单的Mojo:

package com.company.product.plugins;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * @goal diff
 */
public class CCDiffMojo extends AbstractMojo {

    /**
     * @parameter expression="${ccdiff.run}" default-value="true"
     */
    private boolean run;

    public void execute() throws MojoExecutionException {
        if (run) {
            getLog().info("Executing...");
            // TODO: Execute.
        } else {
            getLog().info("Skipping.");
        }
    }
}

pom.xml内容:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.product.plugins</groupId>
    <artifactId>ccdiff</artifactId>
    <packaging>maven-plugin</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Content Catalog Diff</name>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>
</project>

这几乎都来自Maven plugin development guide

所以,看来我能做到:

$ mvn com.company.product.plugins:ccdiff:diff

这可以执行分支,我将在这个自定义工具的逻辑中(它是一种XML差异)。布尔参数是一个标志,允许某人在构建较大的项目时关闭执行。但是,当我尝试:

$ mvn com.company.product.plugins:ccdiff:diff -Dccdiff.run=false

它仍显示“正在执行...”消息,这意味着参数未因某种原因而被设置。

有什么想法吗?我觉得这只是其中一个“D'哦!”错误。

1 个答案:

答案 0 :(得分:0)

您的目标称为diff ... @goal diff,因此请尝试不带'cc'的命令行,如下所示:

$ mvn com.company.product.plugins:ccdiff:diff -Ddiff.run=false

编辑:取2。

我按照你的方式创建了项目,它就像你拥有它一样对我有用 我正在运行maven 2.2.1,这是输出:

C:\java\ws\ccdiff>set MAVEN_OPTS=-DXms_1024M -DXmx=2048M
[INFO] Scanning for projects...
[INFO] artifact com.company.product.plugins:ccdiff: checking for updates from central
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.company.product.plugins:ccdiff:maven-plugin:1.0-SNAPSHOT
[INFO]    task-segment: [com.company.product.plugins:ccdiff:diff]
[INFO] ------------------------------------------------------------------------
[INFO] [ccdiff:diff {execution: default-cli}]
[INFO] Executing...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Tue Nov 23 16:27:10 CAT 2010
[INFO] Final Memory: 1M/4M
[INFO] ------------------------------------------------------------------------
C:\java\ws\ccdiff>mvn com.company.product.plugins:ccdiff:diff -Dccdiff.run=false

C:\java\ws\ccdiff>set MAVEN_OPTS=-DXms_1024M -DXmx=2048M
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.company.product.plugins:ccdiff:maven-plugin:1.0-SNAPSHOT
[INFO]    task-segment: [com.company.product.plugins:ccdiff:diff]
[INFO] ------------------------------------------------------------------------
[INFO] [ccdiff:diff {execution: default-cli}]
[INFO] Skipping.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Nov 23 16:27:20 CAT 2010
[INFO] Final Memory: 1M/4M
[INFO] ------------------------------------------------------------------------
C:\java\ws\ccdiff>