简体   繁体   中英

Is Gradle 5 compatible with the Groovy @Field annotation?

I've been experiencing an issue with the @Field Groovy annotation isn't working when I upgrade from Gradle 4 to Gradle 5.

The error is:
Cannot get the value of write-only property '<varname>' for script of type <typename>

A very in depth description of the issue has been posted here: https://discuss.gradle.org/t/gradle-5-0-field-variable-visibility-issue/

If there is a known issue please provide a link. Otherwise any ideas for how to fix this would be greatly appreciated.

I did not find an answer to why this is happening. I did find a solution.

Replace @Field variables with the ExtraPropertiesExtension .

Old:

@Field String outputJson = 'db.json'

New:

ext {
    outputJson = 'db.json'
}

Now you'll be able to refer to outputJson anywhere in the script just as you were able to on Gradle 4 with @Field annotation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM