3

我正在尝试使用 gmaven 覆盖 maven 中的以下属性:

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>setproperty</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                pom.properties['main.build.directory']=project.parent.build.directory.absolutePath.replace('\\','/');
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

但我得到这个错误:;

[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.5:execute (setproperty) on project my-project: startup failed, script139276
2592853.groovy: 1: expecting ''', found '<EOF>' @ line 1, column 84.
[ERROR] 1 error

上面的 groovy 代码片段有什么问题?

4

2 回答 2

4

使用 gmavenplus-plugin 设置的属性值在使用插件访问时正确显示。即使使用同一插件的不同实例访问它,它也会正确显示。当已经在插件外部初始化的属性的值被插件更改并在插件外部访问时,就会出现问题。现在属性的值不是插件更新的值。更新的值现在在插件范围内。如果某个属性必须由插件更新并且需要在插件范围之外访问,则作为解决此问题的解决方法:不要声明或初始化它,以防它需要然后通过声明和初始化属性插入。

于 2015-07-30T16:50:47.610 回答
1

我同意@khmarbaise 的观点,这有点奇怪,但如果你必须......我不确定为什么它不起作用。该插件不再真正维护。<samelessPlug>我认为这应该可行:

<plugin>
  <groupId>org.codehaus.gmavenplus</groupId>
  <artifactId>gmavenplus-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <id>setproperty</id>
      <phase>validate</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <scripts>
          <script><![CDATA[project.properties['main.build.directory']=project.parent.build.directory.replace('\\','/')]]></script>
        </scripts>
      </configuration>
    </execution>
  </executions>
</plugin>

有关此 mojo 的更多信息,请查看http://groovy.github.io/GMavenPlus/execute-mojo.html。</samelessPlug>。但是,请注意,我相信这将在插件范围内。

于 2014-02-21T22:19:22.050 回答