使用groovy语法的Maven gmavenplus-plugin问题

时间:2019-05-30 07:30:33

标签: maven groovy

我正在尝试使用gmavenplus-plugin自定义Maven构建过程。 确切地说,我在gmaven-plugin中有一个workig脚本,我正尝试在gmavenplus-plugin中重新实现它(此广告是对GMaven的重写)

我正在运行的gmaven代码

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                    println(project.version)
                    println([1, 2, 3])
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

我试图用gmavenplus重写它:

<plugin>
    <groupId>org.codehaus.gmavenplus</groupId>
    <artifactId>gmavenplus-plugin</artifactId>
    <version>1.7.0</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>execute</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <scripts>
            println(project.version)
            println([1, 2, 3])
        </scripts>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.1</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

哪个失败

[ERROR] Script1.groovy: 2: unexpected token: 1 @ line 2, column 34.
[ERROR] println([1
[ERROR] ^
[ERROR] 
[ERROR] 1 error

我尝试使用的任何常规语法都会失败。

更新 CDATA没有帮助。

<scripts>
<![CDATA[
println(project.version)
println([1, 2, 3])
]]>

1 个答案:

答案 0 :(得分:1)

根据示例https://github.com/groovy/GMavenPlus/wiki/Examples

<script>中应该有<scripts>

在以下示例mvn gplus:execute中使用pom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>test-gmavenplus</groupId>
    <artifactId>test-gmavenplus</artifactId>
    <packaging>pom</packaging>
    <version>1.1.0-SNAPSHOT</version>
    <name>test gmavenplus</name>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>1.7.0</version>
        <executions>
          <execution>
            <goals>
              <goal>execute</goal>
            </goals>
          </execution>
        </executions>
      <configuration>
        <scripts>
          <script><![CDATA[
            println "hello `${project.name}`"
          ]]></script>
        </scripts>
      </configuration>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>2.5.7</version>
          <type>pom</type>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
  </build>
</project>