davidasync
12/12/2018, 4:49 PM➜ life-drain git:(master) ✗ ./gradlew build && java -jar build/libs/life-drain-1.0-SNAPSHOT.jar
w: /home/kotl/repo/watchanimeonline/life-drain/src/main/kotlin/com/life/drain/libs/GetMovieUrls.kt: (65, 33): Unnecessary non-null assertion (!!) on a non-null receiver of type List<String>
BUILD SUCCESSFUL in 3s
6 actionable tasks: 6 executed
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/functions/Function1
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.functions.Function1
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
davidasync
12/12/2018, 4:50 PMbuild.gradle
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
}
group 'life-drain'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
apply plugin: 'application'
mainClassName = "com.life.drain.Main"
sourceSets {
main {
kotlin {
srcDir 'src'
}
}
}
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task sitemapGen(type: JavaExec) {
main = 'com.life.drain.scripts.sitemapGenerator.Main'
classpath = sourceSets.main.runtimeClasspath
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jsoup:jsoup:latest.release"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:latest.release"
implementation "org.litote.kmongo:kmongo-coroutine:latest.release"
implementation "com.github.slugify:slugify:latest.release"
implementation "com.google.code.gson:gson:latest.release"
implementation "com.github.dfabulich:sitemapgen4j:latest.release"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
davidasync
12/12/2018, 4:50 PMMrNiamh
12/12/2018, 4:51 PMCasey Brooks
12/12/2018, 4:51 PMjava -jar
command is only supplying the main jar, but none of its dependencies. Why not use the Gradle Application plugin or a JavaExec task https://docs.gradle.org/current/userguide/application_plugin.html https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.htmldavidasync
12/12/2018, 4:53 PMdavidasync
12/12/2018, 4:54 PMdiesieben07
12/12/2018, 4:56 PMCasey Brooks
12/12/2018, 4:57 PMdavidasync
12/12/2018, 5:09 PMStevieB
12/12/2018, 6:46 PMdependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.2-eap13")
compile("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:0.30.2-eap13")
compile("org.jetbrains.kotlinx:kotlinx-coroutines-javafx:0.30.2-eap13")
compile("no.tornado:tornadofx:1.7.17")
compile("de.jensd:fontawesomefx:8.9")
compile("org.controlsfx:controlsfx:8.40.14")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-XXLanguage:+InlineClasses")
}
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = mainClass
}
}
val fatJar = task("fatJar", type = Jar::class) {
baseName = "${project.name}-fat"
manifest {
attributes["Main-Class"] = mainClass
}
from(configurations.runtime.map { if (it.isDirectory) it else zipTree(it) })
with(tasks["jar"] as CopySpec)
}
I am far from a gradle kts expert but I have this one which works, I use the runtime config to produce fat jar and have compile dependencies, you have collected the compile config and have runtime dependencies, maybe the compile carries forward to the runtime but not vice versa
🤷🏻♂️davidasync
12/13/2018, 2:52 PM