【问题标题】:Setting properties in maven with gmaven使用 gmaven 在 maven 中设置属性
【发布时间】:2015-07-31 00:50:47
【问题描述】:

我正在尝试使用 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 sn-p 有什么问题?

【问题讨论】:

  • 为什么需要更改 main.build.directory 并使用 project.parent ?可以详细说明一下...
  • 它是构建转换中临时步骤的一部分 - 一些旧的遗留代码稍后将被删除。但现在我们需要操作内置属性

标签: maven groovy gmaven-plugin


【解决方案1】:

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

【讨论】:

  • 我想在这里添加。线索是实例和继承: pom 是从 gmaven 插件看到的父级。它只支持@Aditya 描述的新属性。但是对于另一个实例,如不同的插件,您可以覆盖和使用现有属性。例如,在同一个 pom 中定义的 maven-site-plugin 中,您可以先覆盖 gmaven 脚本中的属性,然后可以将其与 site.xml 中的新值一起使用。
【解决方案2】:

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

<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>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2015-04-18
    • 2013-09-05
    • 2011-11-25
    • 2012-12-17
    • 1970-01-01
    相关资源
    最近更新 更多