2010-11-22 48 views
1

這應該很簡單 - 我想我只是忽略了一些東西。我有一個簡單的Mojo:簡單的Maven 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的diff)的分支。布爾參數是一個標誌,允許某人在構建較大的項目時關閉執行。然而,當我嘗試:

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

它仍然顯示「執行...」消息,這意味着該參數不獲取設置的某些原因。

任何想法?我覺得這只是其中的一個「哦,哦!」錯誤。

回答

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> 
+0

不,這仍然無法正常工作。我有引用`ccdiff.run`的參數表達式,我認爲它需要匹配。我會嘗試將其改爲`$ {diff.run}`來查看它是否有效(Ed。No dice)。 – emptyset 2010-11-22 21:13:44