Groovy generated constructor missing at compile time

I have a setup in which I call the generated constructor (@TupleConstructor) of the Groovy (Product) class from the java (ProductService) class. The IDE shows the generated constructors and compilation used to work. But now, for unknown reasons, the compilation failed because the compiler no longer finds parameterized constructors:

ProductService.java:31: error: constructor Product in class Product cannot 
be applied to given types; 
required: no arguments  
found: String,boolean,boolean,float 
reason: actual and formal argument lists differ in length

      

And this is my current gradle (2.4) installation:

apply plugin: 'groovy'
apply plugin: 'java'

project.sourceCompatibility = 1.8
project.targetCompatibility = 1.8

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDir 'src/main/java'
...
dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.+'
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}

      

Groovy class:

@TupleConstructor
class Product {
    String name
    boolean bool1
    boolean bool2
    float price
}

      

Constructor query in Java class (not compiled):

...
products.add(new Product("Parliament", true, false, 10.50F));
...

      

+3


source to share


1 answer


Analysis:

It looks like a joint compilation problem. Most likely the @TupleConstructor transformation is done after Groovy has generated the stub .java files, causing the java part of the compilation to fail. It might work before that because you compiled an independent part of Groovy and then reused the existing class files (no cleanup). Unfortunately, this is a limitation of the stub generator, and there is really no way to fix the problem in Groovy if the transformation needs to stay in the same phase.



Solutions:

  • use the groovy -eclipse batch compiler
  • do not use transformations that run after a stub generator
  • create an assembly of multiple modules in gradle that will compile an independent part of Groovy
+1


source







All Articles