0
votes

I've set the language level to 8 in the IntelliJ project settings, and I've also tried setting it in gradle like this:

   buildscript {
    ext.kotlinVersion = '1.3.41'

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
        google()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

    }

}

allprojects {

    version = '1.0'
    ext {
        appName = "VolumeFlux"
        gdxVersion = '1.9.10'
        roboVMVersion = '2.3.8'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
        visuiVersion = '1.4.2'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }


    apply plugin: 'java'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

}

sourceCompatibility = 1.8
targetCompatibility = 1.8

subprojects {
    apply plugin: 'java'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

project(":desktop") {
    apply plugin: "kotlin"

    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}

project(":core") {
    apply plugin: "kotlin"

    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        api "com.kotcrab.vis:vis-ui:1.3.0"
        api "com.github.czyzby:gdx-kiwi:1.9.1.9.6"
        api "net.dermetfan.libgdx-utils:libgdx-utils:0.13.4"
        api "com.badlogicgames.ashley:ashley:$ashleyVersion"
        api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

        compile "com.kotcrab.vis:vis-ui:$visuiVersion"

    }
}

But for some reason I still get a gradle build error:

...\VolumeFlux.java:79: error: lambda expressions are not supported in -source 7
                stockButtons.forEach(b -> {
                                       ^
  (use -source 8 or higher to enable lambda expressions)
2
I recently had this problem in a multi-module project I was only able to resolve this by putting the xxxCompatibility inside the subprojects {} closure in the top level gradle build file, this was for java ver 13 and gradle ver 6, latest intellij ce.Nigel Savage
@NigelSavage unfortunately this didn’t work.BAR
For my issue I explicitly told intellij to use the external gradle 6.0.1, Settings-> Build, Ex... then at the bottom under Gradle Projects -> Use Gradle From 'Specified Location' and Gradle JVM, where java and gradle vers as above. I think intellij is possibly overriding your xxxCompatibility settings. By setting to the external values possibly gets around this.Nigel Savage
@NigelSavage Still nothing. It's like they are fighting eachother, IntelliJ and Gradle. Likely bug?BAR
could you add more of your build.gradle(s). I am not familiar with the syntax I see here project(":xxx") { plugins, dependencies ect ...}. Normally there would be a top level build file with plugins {..} all-projects {..} subprojects {..} ect.. As I mentioned before I ran into this issue recently with the setup just described and resolved as stated before. docs.gradle.org/current/userguide/multi_project_builds.htmlNigel Savage

2 Answers

0
votes

I recently overcame the incorrect source / target issue above with this gradle setup. Looking at the posted build file I cant see why this is happening everything seems correct.

I am posting an outline of my setup that resolved the incorrect source / target compatiblitiy

top level build.gradle

plugins {
id 'base'
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'  apply false
......
// note apply false
}

allprojects {
group = ".."
version = ".."
repositories {
    mavenCentral()
    jcenter()
    ...
}
ext {
    ...
  }
}

subprojects {
  // only apply plugins common to all subprojects here
  apply  plugin: "org.beryx.runtime"
  apply  plugin: "com.google.protobuf"
  sourceCompatibility = 11
  targetCompatibility = 11
  // only declare dependencies common to all subprojects here
  dependencies {
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.4.2'
    testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')
   }
 }

each subproject will have a build.gradle where you apply plugins that are needed and declared in the top level build file

plugins {
// applied from top level build
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm'
.....
}  

dependencies {
// dependencies here that are unique to the subproject
}

with respect to the issue originally I declared the source / target compatibility in the subproject build file and I ran in to the compatibility issue. It was resolved when I moved it to the subprojects closure block in the top level file.

Note @BAR's use of project(":core") {} is correct see example 2 here. When you use this form then you do not need a build.gradle in the subproject but possibly this leads to intellij / gradle snafu

0
votes

I had to set sourceCompatibility = 1.8 in the subproject's build.gradle settings instead of in the root build.gradle.