Cannot use Java 10 feature "var" with Cuba Studio 2018.3

Hello all,

I am puzzled and annoyed some time now by being unable to use the new Java 10 feature “var” for local declarations within Cuba Studio 2018.3, which might indeed be an IntelliJ problem or me being unable to get all the myriads of JDK settings right. I started off with JDK 1.8 and switched to Java 12, but when compiling I always get following error:

error: cannot find symbol class var

for one of my screens:

@Subscribe
private void onInit(InitEvent event) {
    var x = 5;

The intellisense does not actually mark this line as erroneous, but the compiler does.
As far as I can see, I am using the right compiler and changed all JDK settings to Version 12 and still, the compiler complains (I changed Project structure: Project SDK, Project language level, modules sources language level, Settings: Build, Execution Deployment -> Java compiler).

Does anybody have any idea what might be missing?

Kind regards
Dietmar

I am still unable to solve this really annoying phenomenon. I checked the actual build process and observed, that gradle uses some default compiler option parameters, that cannot be altered within Cuba Studio - language levels will be reset, whenever I refresh gradle settings resulting in following compiler options (only a small selection):
21:59:27.117 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.8 -target 1.8 -d
Even changing compiler options in the build.gradle file has no effect, compiler options seem effectively hardcoded. Any further hints will be appreciated.

Kind regards
Dietmar

Please note that for now we support only 2 LTS versions of Java: JDK 8 and JDK 11.

If you want to use var keyword you will need to set JDK 11 for Gradle in Gradle options and in Project Settings:

Screenshot_20190613_114927

Screenshot_20190613_114947

Finally, set source and target levels in build.gradle and Refresh the project:

configure([globalModule, coreModule, webModule]) {
    // ... 

    sourceCompatibility = '11'
    targetCompatibility = '11'
}
1 Like

Thank you very much, that is very helpful. As I don’t have a JDK 11 installed yet, I need to prepare a fresh install and will report on my progress using your instructions then.

Best regards
Dietmar

Unfortunately, there is no change after performing your instructions. Although I inserted the gradle operations, the language level stays at the Java 8 level (see attachment). It is always reset after refreshing the gradle settings.

Best regards
Dietmar

2019-06-13_23-22-11

configure([globalModule, coreModule, webModule]) {
    // ... 

    sourceCompatibility = '11'
    targetCompatibility = '11'
}

Did you set up this and refresh Gradle project?

I set up the gradle project in this way, please see attachment:

build.gradle (5.2 KB)

Add this to the end of 64-80 lines block, you need to apply these settings after cuba plugin applied.

1 Like

Thank you very much, Yuriy,
that solved my problem finally. I guess I need to polish my gradle skills, sorry for being kind of ignorant regarding proper gradle usage :blush:

Kind regards
Dietmar