https://kotlinlang.org logo
Title
v

ValV

11/06/2018, 4:38 PM
Well, I'm trying to
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
, but it says
Unresolved reference: jetbrains
. So I need
kotlin-gradle-plugin
to installed somehow, right? I have
mavenLocal()
and
mavenCentral()
, how do I get the plugin into local repository and plug outta there?
k

kartikpatodi

11/06/2018, 6:49 PM
try
jcenter()
in the repositories
v

ValV

11/06/2018, 7:28 PM
Nope, this does not help either. Perhaps, I should mention that I'm trying to convert existing build.gradle to build.gradle.kts. Somehow the script which is in Groovy finds
compileKotlin
task, but when I try to do it in Kotlin
.kts
it does not work
k

kartikpatodi

11/06/2018, 7:31 PM
can you share your .kts build file?
v

ValV

11/06/2018, 7:38 PM
k

kartikpatodi

11/06/2018, 7:40 PM
You cannot/should not use buildscript and plugins block in the sae build file
also you no longer need to import the kotlin-grade-plugin
v

ValV

11/06/2018, 7:45 PM
Hmm, that
buildscript { repositories { ... } ... dependencies { ... } }
was in original Groovy build file. Since I'm very new to Gradle and know Groovy a bit better than none, I've ended up with this 😁
k

kartikpatodi

11/06/2018, 7:45 PM
which gradle version are you using?
v

ValV

11/06/2018, 7:46 PM
4.10.2 Linux build
k

kartikpatodi

11/06/2018, 7:47 PM
ok first try this if it works
import java.util.regex.Pattern
import kotlin.reflect.jvm.internal.impl.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    application
    kotlin("jvm") version "1.3.0"
}

val kotlin_version = "1.3.0"
val tornadofx_version = "1.7.16"
val junit_version = "5.1.0"

tasks.withType<KotlinCompile> {//compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

repositories {
    jcenter()
}

dependencies {
    implementation(kotlin("stdlib"))
    implementation("no.tornado:tornadofx:$tornadofx_version")

//    testCompile( "org.junit.jupiter:junit-jupiter-api:$junit_version")
//    testRuntime( "org.junit.jupiter:junit-jupiter-engine:$junit_version")
}

val mainClassName = "com.github.valv.demo.tfx"

val jar by tasks.getting(Jar::class) {
    archiveName = "new.jar"
    //mainClassName = "com.github.valv.demo.tfx"
    manifest {
        attributes( mapOf(
                "Class-Path" to configurations.joinToString(" ") { it.name },
                "Main-Class" to mainClassName
        ))
    }
// TODO: convert to Kotlin
//    from(configurations.compile.collect { entry -> zipTree(entry) }) {
//        exclude( "META-INF/MANIFEST.MF")
//        exclude( "META-INF/*.SF")
//        exclude( "META-INF/*.DSA")
//        exclude( "META-INF/*.RSA")
//    }
}
✔️ 1
v

ValV

11/06/2018, 7:47 PM
OMG, It uses Kotlin 1.2.61, How can I configure 1.3.0?
k

kartikpatodi

11/06/2018, 7:49 PM
sorry?
v

ValV

11/06/2018, 7:54 PM
Yes, that trick with removing
buildscript
block and placing
plugins
ontop solved the problem
Now it finds everything
k

kartikpatodi

11/06/2018, 7:54 PM
Great!!
v

ValV

11/06/2018, 7:55 PM
But the Kotlin version in
gradle --version
is still 1.2.61. I hope it's not terrible
k

kartikpatodi

11/06/2018, 7:55 PM
also forgot to mention use
implementation
instead of
compile
as it is more stable
v

ValV

11/06/2018, 7:58 PM
Aha, I tried exactly
implementation
, but it was not resolved because of the problem above. Now it is. So for tests I should point
testImplementation
and
testRuntime
, right?
k

kartikpatodi

11/06/2018, 7:59 PM
It does not matter actually.. the gradle version you are currently using is build using kotlin 1.2.61 so it is shipped with that vesion.. But if you want to use say kotlin 1.3.0 then just mention 1.3.0 in the plugins block and it will use that version of kotlin in the project
Yes, use
testImplementation
and
testRuntime
v

ValV

11/06/2018, 8:01 PM
Got it, thanks
k

kartikpatodi

11/06/2018, 8:02 PM
👍🏻