gpt4 book ai didi

java - groovy java gmaven 和特征

转载 作者:行者123 更新时间:2023-11-30 03:35:32 25 4
gpt4 key购买 nike

我正在尝试编写测试并使用 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

我检查过类(class)。特质变成:

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

以及实现特征的类:

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

这很公平,我无法实现类。我该如何修复它?

最佳答案

GMaven 无法编译较新版本的 Groovy。我建议转到GMavenPlus (我刚刚根据您的示例成功测试了它)。

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

由于我是 GMavenPlus 的作者(我也维护过 GMaven 一段时间),所以说实话,你的所有选择,还有 Groovy-Eclipse Compiler Plugin for Maven 。我试图帮助人们了解他们的选择here .

关于java - groovy java gmaven 和特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28003992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com