new to both gradle and kotlin, so any help would b...
# gradle
s
new to both gradle and kotlin, so any help would be appreciated.
p
You would have to append
::class.java
after the
KotlinCompile
so
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
would work, but the better way is to use
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
as far as i know the
.all
is not required here And you should then be able to use an import statement to get rid of the
org.jetbrains.kotlin.gradle.tasks.
prefix within the script
👍 1
s
The import wasn't able to find the KotlinCompile class at all, which is what I think the issue is.
n
Make sure that the Kotlin JVM plugin is being applied, eg:
Copy code
plugins {
    kotlin(module = "jvm") version "1.2.51"
}
I'm assuming that a Kotlin JVM project (not Kotlin Native, Kotlin JS, or Kotlin Android) is being developed.
s
yeah, it was being applied. let me post the whole thing.
ah looks like the
withType<>
syntax didn't fail, but I'm still seeing.
CalculatorMessageStructure.kt: (122, 9): Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
Copy code
plugins {
    base
    java
    kotlin("jvm") version "1.2.51"
//    application
}

group = "com.company.loanplatform"
version = "1.0.0-SNAPSHOT-test"

allprojects {
    apply {
        plugin("org.jetbrains.kotlin.jvm")
    }
    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
    }
    dependencies {
        implementation("com.company.enterprise:pt-enterprise-dependencies:0.15.0-SNAPSHOT")
    }
}

dependencies {
    implementation("com.company.enterprise:pt-enterprise-dependencies:0.15.0-SNAPSHOT")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}


tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions {
        suppressWarnings = true
        jvmTarget = "1.8"
    }
}
nothing special about the subproject
Copy code
plugins {
    kotlin("jvm")
}

dependencies {
    implementation("com.company.enterprise:pt-enterprise-dependencies:0.15.0-SNAPSHOT")

    compile(kotlin("stdlib"))
    ...
}
n
Always a good idea to make sure that the version of the Kotlin std lib matches the Kotlin plugin version, otherwise a warning will appear.
s
yeah it does.
But it's not compiling for the proper jvm target, so it doesn't even seem to be picking up the config.
Version: 1.2.51-release-IJ2018.2-1
n
Here is a sample build file:
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "org.example"
version = "0.1-SNAPSHOT"

val kotlinVer = "1.2.51"

repositories {
    jcenter()
    mavenCentral()
}

plugins {
    kotlin(module = "jvm") version "1.2.51"
    application
}

tasks.withType(KotlinCompile::class.java) {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClassName = "org.example.hellokotlin.MainKt"
}

dependencies {
    compile(kotlin(module = "stdlib-jdk8", version = kotlinVer))
}
Change stdlib to stdlib-jdk8 so it looks like this:
Copy code
// ...
dependencies {
    // ...
    compile(kotlin(module = "stdlib-jdk8", version = kotlinVer))
}
s
still seeing that error 😕
n
Try a Gradle refresh and see if that resolves the error.
s
what is a gradle refresh?
n
If you are using IntelliJ there is a Gradle window which contains a refresh button.
s
oh yes, that does not resolve it no. I was mostly running in the command line anyway. I was able to put the tasks block inside of
allprojects
and that mostly works...
n
So a multi-module Gradle project is being used?
s
yes, hence why I was trying to use
.all