自定义DSL在groovy 3.0.x中运行,但在2.5.x中运行时失败

自定义DSL在groovy 3.0.x中运行,但在2.5.x中运行时失败,groovy,Groovy,我有一个奇怪的运行时错误,基于AbstractFactory的定制DSL在groovy 3.0.x下编译并运行良好,但在2.5.x下运行时失败 代码如下: @Test void sayTest() { PerCLScript script = percl.script { say language: 'en-US', loop: 1, conferenceId: 'confId', text: 'some text', enforcePCI: false }

我有一个奇怪的运行时错误,基于AbstractFactory的定制DSL在groovy 3.0.x下编译并运行良好,但在2.5.x下运行时失败

代码如下:

  @Test
  void sayTest() {
    PerCLScript script = percl.script {
      say language: 'en-US', loop: 1, conferenceId: 'confId', text: 'some text', enforcePCI: false
    }

    compare('[{"Say":{"language":"en-US","conferenceId":"confId","text":"some text","enforcePCI":false,"loop":1}}]', script.serializeToPerCL())
  }
运行时错误:

groovy.lang.MissingMethodException: No signature of method: com.freeclimb.groovy.PerCLBuilderTest.say() is applicable for argument types: (LinkedHashMap) values: [[language:en-US, loop:1, conferenceId:confId, text:some text, ...]]
Possible solutions: sms(), any(), any(groovy.lang.Closure), tap(groovy.lang.Closure), wait(), wait(long)
我正在使用GmavenPlus 1.8.1进行构建,但我尝试了EclipseGroovy编译器,得到了相同的结果

      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>1.8.1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>compileTests</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <invokeDynamic>true</invokeDynamic>
        </configuration>
      </plugin>

您的
say
方法是如何定义的?registerFactory('say',new PerCLCommandFactory(say.class))我使用的是FactoryBuilderSupport类。PerCLCommandFactory基于该类创建一个新实例。我认为有一种更好的方法可以使用delegates注释来实现这一点,但这是可行的,我打算稍后再讨论这个问题。@PaulKing我添加了更多的代码细节。谢谢
class PerCLBuilder extends FactoryBuilderSupport {

  private PerCLScript percl

  public PerCLBuilder(boolean init = true) {
    super(init)
  }

  def registerObjectFactories() {
    registerFactory('script', new ScriptFactory())
    registerFactory('say', new PerCLCommandFactory(Say.class))
...

  }

  class PerCLCommandFactory extends AbstractFactory {
    Class clazz;

    PerCLCommandFactory(Class clazz) {
      this.clazz = clazz;
    }

    @SuppressWarnings("GrDeprecatedAPIUsage")
    Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)
        throws InstantiationException, IllegalAccessException {
      clazz.newInstance()
    }
...