我正在尝试编写测试并使用 groovy 特征功能。
这是我的 gmaven 插件配置
<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>
这是我的特点:
trait UserTrait {
String generateCrossId(){
System.currentTimeMillis().toString()
}
String generateOuterKey(){
(System.currentTimeMillis() / new Random().nextInt(1000)) as String
}
}
这是我的测试课:
class UserToCrossIdConnectionTest extends IntegrationBaseTest implements UserTrait{}
我正在尝试使用 maven 编译这些东西,我得到:
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
我检查了课程。特质变成:
@groovy.transform.Trait() public class UserTrait
extends java.lang.Object implements
groovy.lang.GroovyObject {}
和实现特征的类:
public class UserToCrossIdConnectionTest
extends IntegrationBaseTest implements
ru.mycode.UserTrait {
这很公平,我无法实现类。我该如何解决?