maven-antrun-plugin:scriptdef在添加元素时忽略CDATA

时间:2017-12-13 15:32:29

标签: maven ant maven-3 maven-antrun-plugin

我正在使用maven 3.5.0并尝试使用maven-antrun-plugin运行一个简单的javascript代码(处理文件集)。在他自己的build.xml中,它可以工作,当从maven-antrun-plugin调用时,它也可以工作。但是,如果我想将整个build.xml放在maven-antrun-plugin的配置中,它就不会按预期工作。

最小的pom.xml(脚本在这里不使用文件集,它只是一个测试用例):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stackoverflow</groupId>
    <artifactId>test-antrun</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>hello</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <scriptdef name="hello" language="javascript" classpathref="maven.plugin.classpath">
                                    <element name="fileset" type="fileset"></element>
<![CDATA[
      java.lang.System.out.println("Hello World!");
]]>
                                </scriptdef>
                                <hello>
                                    <fileset id="stuff" dir="stuff">
                                    </fileset>
                                </hello>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

如果我跑:

mvn antrun:run@hello

没有“Hello World!”打印在标准输出中,这是我在target / antrun文件夹中找到的build-main.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main"  >
<target name="main">
  <scriptdef name="hello" language="javascript" classpathref="maven.plugin.classpath">
    <element name="fileset" type="fileset"></element>
  </scriptdef>
  <hello>
    <fileset id="stuff" dir="stuff"></fileset>
  </hello>
</target>
</project>

如您所见,CDATA被剥离。但是,如果我从 hello 中删除 scriptdef fileset 中的元素,生成的build-main.xml就是这个:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main"  >
<target name="main">
  <scriptdef name="hello" language="javascript" classpathref="maven.plugin.classpath">java.lang.System.out.println(&quot;Hello World!&quot;);</scriptdef>
  <hello></hello>
</target>
</project>

我得到了这个输出:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-antrun 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (hello) @ test-antrun ---
[INFO] Executing tasks

main:
Hello World!
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.641 s
[INFO] Finished at: 2017-12-13T16:21:51+01:00
[INFO] Final Memory: 6M/18M
[INFO] ------------------------------------------------------------------------

我是否遗漏了某些内容,或者这是maven-antrun-plugin中的错误/缺失功能?

编辑:我在jira上打开了一个问题:https://issues.apache.org/jira/browse/MANTRUN-207

0 个答案:

没有答案