groovy 3.0.9 导入静态变量不起作用

发布于 2025-01-09 13:22:44 字数 2394 浏览 1 评论 0原文

我已经从 groovy 2.4.10 升级到 3.0.9,它破坏了静态变量导入。我正在使用 groovy-eclipse-compiler。以下是一些实现和错误详细信息(我创建了一个重现该行为的最小存储库。以下是链接: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-compiler 的版本。有任何指示这里有什么问题吗?

I have upgraded from groovy 2.4.10 to 3.0.9 and it broke the static variable imports. I am using groovy-eclipse-compiler. Here are some implementation and the error details (I have created a minimal repo that reproduces the behavior. here's the link: https://github.com/avdhut1222/demo):

Dependency

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>3.0.9</version>
    <type>pom</type>
</dependency>

Groovy Plugins

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

Source class

package com.srcpkg

class SrcClass {
   static SomeClass staticVar
}

Destination class

package com.destpkg

import static com.srcpkg.SrcClass.staticVar

class DestClass {
   method1 () {
      String str = staticVar.str1
   }
}

Error

ERROR in DestClass.groovy (at line 3)
    import static com.srcpkg.SrcClass.staticVar
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
The field SrcClass.com.srcpkg.SrcClass.staticVar is not visible

The static imports used to work with groovy 2.4.10 and corresponding versions of groovy-eclipse-compiler. Any pointers what's the issue here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞美少年 2025-01-16 13:22:44

感谢@emiles 的回答(以上评论)。在此处发布目标类的更新代码

package com.destpkg

import static com.srcpkg.SrcClass.getStaticVar

class DestClass {
   method1 () {
      String str = staticVar.str1
   }
}

Thanks to @emilles for the answer (above comments). Posting the updated code here for destination class

package com.destpkg

import static com.srcpkg.SrcClass.getStaticVar

class DestClass {
   method1 () {
      String str = staticVar.str1
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文