2012-03-08 87 views
0

我想創建一個Maven的螞蟻定製插件,基於多個構建腳本。有關它的文檔中有一個註釋:http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html(請參閱「有關多個構建腳本的註釋」),但我無法使其工作。螞蟻插件:找不到依賴

下面是腳本:

<root>\src\main\scripts\A.build.xml 
----------------------------------- 
<project> 
    <import file="C.build.xml"/> 
    <target name="hello" depends="dependency"> 
     <echo>Hello, World</echo> 
    </target> 
</project> 

<root>\src\main\scripts\A.mojos.xml 
----------------------------------- 
<pluginMetadata> 
    <mojos> 
     <mojo> 
      <goal>hello</goal> 
      <call>hello</call> 
     </mojo> 
    </mojos> 
</pluginMetadata> 

<root>\src\main\scripts\B.build.xml 
----------------------------------- 
<project> 
    <target name="hello"> 
     <echo>Hello, World</echo> 
    </target> 
</project> 

<root>\src\main\scripts\B.mojos.xml 
----------------------------------- 
<pluginMetadata> 
    <mojos> 
     <mojo> 
      <goal>hello2</goal> 
      <call>hello</call> 
     </mojo> 
    </mojos> 
</pluginMetadata> 

<root>\src\main\scripts\C.build.xml 
----------------------------------- 
<project> 
    <target name="dependency"> 
     <echo>This is the dependency</echo> 
    </target> 
</project> 

<root>\pom.xml 
-------------- 
<project> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.myproject.plugins</groupId> 
    <artifactId>hello-plugin</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <packaging>maven-plugin</packaging> 

    <name>Hello Plugin</name> 

    <dependencies> 
     <dependency> 
      <groupId>org.apache.maven</groupId> 
      <artifactId>maven-script-ant</artifactId> 
      <version>2.2.1</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-plugin-plugin</artifactId> 
       <version>2.9</version> 

       <dependencies> 
        <dependency> 
         <groupId>org.apache.maven.plugin-tools</groupId> 
         <artifactId>maven-plugin-tools-ant</artifactId> 
         <version>2.9</version> 
        </dependency> 
       </dependencies> 

       <configuration> 
        <goalPrefix>hello</goalPrefix> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

在根層次,我跑 「MVN全新安裝」,這是成功的。

然後我跑 「MVN org.myproject.plugins:HELLO-插件:hello2」,這也是成功的,產生了 「你好,世界」 輸出。

但是,在運行 「MVN org.myproject.plugins:HELLO-插件:您好」 的時候,我得到這個:

[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Hello Plugin 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin --- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.531s 
[INFO] Finished at: Thu Mar 08 12:52:25 PST 2012 
[INFO] Final Memory: 3M/15M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.myproject.plugins:hello-plugin:1.0-SNAPSHOT:hello (default-cli) on project hello-plug 
in: Failed to execute: Executing Ant script: A.build.xml [hello]: Failed to parse. Cannot find C.build.xml imported from 
C:\DOCUME~1\joanes\LOCALS~1\Temp\plexus-ant-component9129296102162378706.build.xml -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

我的問題是一個人如何使這項工作?通過查看錯誤,腳本在臨時文件夾中執行,因此無法找到導入的C.build.xml。有沒有辦法改變它?推薦的方法是什麼?

+0

它獨立運行,即如果您運行'ant -f A.build.xml hello' – Raghuram 2012-03-09 03:57:08

+0

是的,我得到所需的輸出(「這是一個依賴項」和「你好,Wolrd」)。 – 2012-03-09 22:23:05

回答

0

嘗試使用:import file =「$ {basedir} /src/main/scripts/C.build.xml」。看來maven正在重寫或將腳本複製到臨時目錄,然後在那裏執行它。然後嘗試從該目錄導入C.build.xml,因爲沒有其他路徑信息用於C.build.xml。

+0

按照建議的工作方式更改導入,但僅限於從基礎目錄運行(上述示例中的)。 – 2012-03-09 22:26:41

+0

當從另一個目錄中運行,讓我們說,我得到: [錯誤]未能執行目標org.myproject.plugins:HELLO-插件:1.0快照:你好項目測試(默認CLI):未能執行:執行Ant腳本:A.build.xml [hello]:解析失敗。無法找到從C:\ DOCUME〜1 \ joanes \ LOCALS〜1 \ Temp \ plexus-ant-component4838685001229146307.build.xml - > [Help 1] – 2012-03-09 22:30:10

+0

導入的 /src/main/scripts/C.build.xml基本上, $ {basedir}被解析爲當前目錄:( – 2012-03-09 22:30:50