2012-03-08 112 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