stask
11/21/2020, 6:57 AMjava -jar server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
...
I googled, that the problem is in kotlin library, which should be packed into the jar in a specific way. Documentation here https://www.jetbrains.com/help/idea/create-your-first-kotlin-app.html?section=Gradle%20Groovy tells me, that I should add special code in build.gradle. There is my code on the picture. As you can see, "from" is grey...
And I get next error for Gradle
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'server'.
<131 internal calls>
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method jar() for arguments [build_c5anurhkrrlxlaf3i7moe4k0u$_run_closure5@7f80db22] on task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.
at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:182)
at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:166)
at org.gradle.api.internal.tasks.DefaultTaskContainer_Decorated.invokeMethod(Unknown Source)
at build_c5anurhkrrlxlaf3i7moe4k0u.run(/Users/stask/projects/motionLearning/chat/kotlinServer/server/build.gradle:100)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
... 130 more
Could you help me, how to fix the build?Vampire
11/21/2020, 10:09 AMapplication
plugin to build a proper distribution archive with everything you need (your code, your libs, generated start scripts for Windows and *nix, ...) by just applying one plugin and setting one propertyk https://docs.gradle.org/current/userguide/application_plugin.htmlstask
11/21/2020, 4:13 PMstask
11/21/2020, 5:30 PMapplication {
mainClass = 'broccole.Server'
executableDir = 'out/bin'
}
and run from cmd
gradle distZip
Am I right?Vampire
11/21/2020, 5:32 PMout/bin
in the final archive, then yesstask
11/21/2020, 5:34 PMstask
11/21/2020, 5:36 PMjvmJar {
dependsOn(jsBrowserProductionWebpack)
from(new File(jsBrowserProductionWebpack.entry.name, jsBrowserProductionWebpack.outputPath))
}
task run(type: JavaExec, dependsOn: [jvmJar]) {
group = "application"
main = "broccole.Server"
classpath(configurations.jvmRuntimeClasspath, jvmJar)
args = []
}
stask
11/21/2020, 5:39 PMstask
11/22/2020, 2:18 AMstask
11/22/2020, 2:19 AMkotlin {
jvm() {
withJava()
jvmJar {
manifest {
attributes 'Main-Class': 'broccole.Server'
}
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}
}
...
Vampire
11/23/2020, 2:35 AMapplication
plugin.
To build a proper distribution with the application
plugin you indeed need a little bit more boilerplate.
But I would still prefer that anytime over building a fat jar.
I just tried and this should work fine:
application {
mainClass = 'broccole.Server'
}
def runtimeClasspath = files()
runtimeClasspath.from(configurations.jvmRuntimeClasspath)
runtimeClasspath.from(jvmJar)
run {
classpath = runtimeClasspath
}
startScripts {
classpath = runtimeClasspath
}
distributions {
main {
contents {
into('lib') {
from(runtimeClasspath)
}
}
}
}
It fixes up the run
task, the startScripts
generation task and the distribution copy spec and thus the installDist
, distZip
and distTar
tasks.stask
11/25/2020, 8:58 PMstask
12/05/2020, 2:22 PM