我已经从groovy 2.4.10升级到3.0.9,它打破了静态变量导入。我使用的是groovy eclipse编译器。以下是一些实现和错误详细信息(我创建了一个复制行为的最小repo。以下是链接:https://github.com/avdhut1222/demo):
依赖
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.9</version>
<type>pom</type>
</dependency>
Groovy插件
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.8-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.7.0</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.8-01</version>
</dependency>
</dependencies>
</plugin>
源类
package com.srcpkg
class SrcClass {
static SomeClass staticVar
}
目的地类别
package com.destpkg
import static com.srcpkg.SrcClass.staticVar
class DestClass {
method1 () {
String str = staticVar.str1
}
}
错误
ERROR in DestClass.groovy (at line 3)
import static com.srcpkg.SrcClass.staticVar
^^^^^^^^^^^^^^^^^^^^^^^^^^
The field SrcClass.com.srcpkg.SrcClass.staticVar is not visible
静态导入用于groovy 2.4.10和groovy eclipse编译器的相应版本。有什么问题吗?
感谢@emilles的回答(以上评论(。在此处张贴目的地类别的更新代码
package com.destpkg
import static com.srcpkg.SrcClass.getStaticVar
class DestClass {
method1 () {
String str = staticVar.str1
}
}