基于多个构建脚本的Maven的Ant插件:找不到依赖项



我正在尝试基于多个构建脚本为Maven创建一个自定义的ant插件。文档中有一条注释:http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html(请参阅"关于多个构建脚本的说明"),但我还没能使它发挥作用。

以下是脚本:

<root>srcmainscriptsA.build.xml
-----------------------------------
<project>
    <import file="C.build.xml"/>
    <target name="hello" depends="dependency">
        <echo>Hello, World</echo>
    </target>
</project>
<root>srcmainscriptsA.mojos.xml
-----------------------------------
<pluginMetadata>
    <mojos>
        <mojo>
            <goal>hello</goal>
            <call>hello</call>
        </mojo>
    </mojos>
</pluginMetadata>
<root>srcmainscriptsB.build.xml
-----------------------------------
<project>
    <target name="hello">
        <echo>Hello, World</echo>
    </target>
</project>
<root>srcmainscriptsB.mojos.xml
-----------------------------------
<pluginMetadata>
    <mojos>
        <mojo>
            <goal>hello2</goal>
            <call>hello</call>
        </mojo>
    </mojos>
</pluginMetadata>
<root>srcmainscriptsC.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-clean-install",这是成功的。

然后我运行"mvn.myproject.plugins:hello-plugin:hello2",它也很成功,并产生了"hello,World"输出。

然而,当运行"mvn.org.myproject.plugins:hello-plugin: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~1joanesLOCALS~1Tempplexus-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。有办法改变这一点吗?建议采用什么方法来实现这一点?

尝试使用:import file="${basedir}/src/main/scripts/C.build.xml"。看起来maven正在重写或复制脚本到临时目录,然后在那里执行它。然后,它尝试从该目录导入C.build.xml,因为C.build.xml没有其他路径信息。

相关内容

  • 没有找到相关文章

最新更新