1

I'm trying to write test and use groovy trait feature.

Here is my gmaven plugin configuration

<plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <debug>false</debug>
                    <verbose>true</verbose>
                    <stacktrace>true</stacktrace>
                    <providerSelection>2.0</providerSelection>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>generateStubs</goal>
                            <goal>testCompile</goal>
                            <goal>generateTestStubs</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>2.3.0</version>
                    </dependency>
                </dependencies>
            </plugin>

Here is my trait:

trait UserTrait {

    String generateCrossId(){
        System.currentTimeMillis().toString()
    }

    String generateOuterKey(){
        (System.currentTimeMillis() / new Random().nextInt(1000)) as String
    }
}

Here is my test class:

class UserToCrossIdConnectionTest extends IntegrationBaseTest implements UserTrait{}

I'm trying to compile this stuff using maven and i get:

INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 21 source files to /project/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /project/target/generated-sources/groovy-stubs/test/ru/mycode/UserControllerTest.java:[12,33] interface expected here
[ERROR] /project/target/generated-sources/groovy-stubs/test/ru/mycode/UserToCrossIdConnectionTest.java:[12,33] interface expected here
[INFO] 2 errors 

I've checked the classes. Trait became:

@groovy.transform.Trait() public class  UserTrait
  extends java.lang.Object  implements
    groovy.lang.GroovyObject {}

and class which implements trait:

public class  UserToCrossIdConnectionTest
  extends IntegrationBaseTest  implements
    ru.mycode.UserTrait {

That's fair, I can't implement class. How can i fix it?

Keegan
  • 11,345
  • 1
  • 25
  • 38
Capacytron
  • 3,425
  • 6
  • 47
  • 80

1 Answers1

2

GMaven isn't able to compile newer versions of Groovy. I suggest moving to GMavenPlus (I just successfully tested it against your example).

<plugin>
    <groupId>org.codehaus.gmavenplus</groupId>
    <artifactId>gmavenplus-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <goals>
          <goal>addSources</goal>
          <goal>addTestSources</goal>
          <goal>generateStubs</goal>
          <goal>compile</goal>
          <goal>testGenerateStubs</goal>
          <goal>testCompile</goal>
          <goal>removeStubs</goal>
          <goal>removeTestStubs</goal>
        </goals>
      </execution>
    </executions>
</plugin>

Since I'm the author of GMavenPlus (I also maintained GMaven for a while), to be honest about all your options, there's also Groovy-Eclipse Compiler Plugin for Maven. I tried to help people understand their options here.

Keegan
  • 11,345
  • 1
  • 25
  • 38
  • Hi, met problem with traits from other angle. I have a trait with concrete and abstract method. And two classes, they implement and override abstract method. I get compilation error: java complains that two classes doesn't override concrete method from trait... Should I start new question? – Capacytron Aug 25 '15 at 16:49
  • Yes, please start a new question. – Keegan Aug 25 '15 at 17:13
  • http://stackoverflow.com/questions/32224258/cant-compile-trait-using-gmavenplus-plugin could you see please? – Capacytron Aug 26 '15 at 14:18