开发者

static import not working in Groovy 1.7.4?

开发者 https://www.devze.com 2023-01-14 11:30 出处:网络
I can\'t get static imports to work in Groovy. Is this supposed to work? (I\'m running Groovy 1.7.4 on Windows)

I can't get static imports to work in Groovy. Is this supposed to work?

(I'm running Groovy 1.7.4 on Windows)

Constants.groovy:

package foo

class Constants {
    static final PI = 3.14
}

Test.groovy:

package foo
import static foo.Constants.PI

class Test {
    static main(args) {
        println("pi=" + PI)
    }
}

EDIT: Both files are stored in the same directory "foo".

When I try to run thi开发者_运维百科s I get:

groovy -cp . foo\Test.groovy
Caught: groovy.lang.MissingPropertyException: No such property: PI for class: foo.Test
        at foo.Test.main(Test.groovy:6)


This problem was reported as issue [Groovy-4386], and is now fixed in Groovy 1.7.6


This is a problem with groovy's dependency resolution. You can work around it by forcing it to compile Constants.groovy first, like so:

groovyc foo/Constants.groovy
groovy foo/Test.groovy

EDIT: downgrading groovy to version 1.7.3 also solves this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号