janvladimirmostert
04/24/2019, 8:32 AMtasks.withType<KotlinCompile> {
incremental = true
kotlinOptions.jvmTarget = "1.8"
}
builds that usually took 1 minute are now taking 7-15 minutes, not sure if it's due to the code-base growing pass a certain point that's now causing this slowdown, new intellij version, new kotlin version or any of several dozen permutations of things that could have changed.
i want to see if giving the compiler more memory will speed up compile times or get it back to "normal"gildor
04/24/2019, 8:33 AMgildor
04/24/2019, 8:33 AMjanvladimirmostert
04/24/2019, 8:34 AMgildor
04/24/2019, 8:35 AMgildor
04/24/2019, 8:36 AMgildor
04/24/2019, 8:36 AMjanvladimirmostert
04/24/2019, 11:37 AMcompileKotlin
and then after 25 minutes, i kill it.
I've done the build scan, and it gave suggestions to add some extra params in the gradle.properties
file:
org.gradle.caching=true
#org.gradle.console=rich
org.gradle.console=verbose
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
kotlin.incremental=true
running --scan doesn't do anything if the build doesn't complete.
This is a mixed Java + Kotlin project (only two or three Java classes), all the Java sources are in src/main/java and Kotlin sources are in src/main/kotlin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.daemon.common.configureDaemonJVMOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "<http://za.co|za.co>. ......"
version = "1.2.0"
description = " ......"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
application {
mainClassName = " ......"
}
plugins {
val kotlinVersion = "1.3.30"
application
kotlin("jvm").version(kotlinVersion )
java
maven
id("com.github.johnrengelman.shadow").version("2.0.4")
id("org.jetbrains.kotlin.plugin.noarg").version(kotlinVersion)
}
tasks.withType<ShadowJar> {
baseName = "app"
}
repositories {
mavenLocal()
jcenter()
maven("<http://repo.maven.apache.org/maven2>")
}
tasks.withType<Jar> {
manifest {
attributes(mapOf(
"Main-Class" to " ......",
"mainClassName" to " ......"
))
}
}
apply {
plugin("org.jetbrains.kotlin.plugin.noarg")
}
tasks.withType<KotlinCompile> {
incremental = true
kotlinOptions.jvmTarget = "1.8"
}
dependencies {
...
}
janvladimirmostert
04/24/2019, 12:00 PMgradle build --debug --warning-mode=all --full-stacktrace --console=verbose
now
seeing lots of 13:59:51.497 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
13:59:53.695 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting OS memory status event {Total: 17179869184, Free: 5305978880}
13:59:53.695 [DEBUG] [org.gradle.launcher.daemon.server.health.LowMemoryDaemonExpirationStrategy] Received memory status update: {Total: 17179869184, Free: 5305978880}
13:59:53.695 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting JVM memory status event {Maximum: 7635730432, Committed: 487587840}
janvladimirmostert
04/24/2019, 12:08 PMjanvladimirmostert
04/24/2019, 12:15 PMjanvladimirmostert
04/24/2019, 12:28 PMgildor
04/24/2019, 12:37 PMgildor
04/24/2019, 12:38 PMgildor
04/24/2019, 12:46 PMjanvladimirmostert
04/24/2019, 12:48 PMjanvladimirmostert
04/24/2019, 12:49 PMRemoved java?i had java and kotlin under plugins, seems that the kotlin plugin compiles java too, so no need for that. Not sure if the kotlin and java plugins are locking resources or something
gildor
04/24/2019, 12:51 PMgildor
04/24/2019, 12:51 PMgildor
04/24/2019, 12:52 PMjanvladimirmostert
04/24/2019, 12:52 PMjanvladimirmostert
04/24/2019, 12:52 PMjanvladimirmostert
04/24/2019, 12:52 PMid("com.github.johnrengelman.shadow").version("2.0.4")
janvladimirmostert
04/24/2019, 12:53 PMgildor
04/24/2019, 12:53 PMgildor
04/24/2019, 12:55 PMjanvladimirmostert
04/24/2019, 12:56 PMjanvladimirmostert
04/24/2019, 1:01 PMjanvladimirmostert
04/24/2019, 1:01 PMjanvladimirmostert
04/24/2019, 1:02 PMjanvladimirmostert
04/24/2019, 1:02 PMsnowe
04/24/2019, 1:20 PMjanvladimirmostert
04/24/2019, 1:22 PMapplication {
mainClassName = "AppApi"
}
or even this:
tasks.withType<ShadowJar> {
manifest.attributes.put("Main-Class", application.mainClassName)
}
but there's no "Main-Class" in the manifest, so yes, it actually finishes building, but the shadow jar doesn't work at alljanvladimirmostert
04/24/2019, 1:24 PMtasks.withType<Jar> {
manifest.attributes.put("Main-Class", application.mainClassName)
}
gives a JNI error
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/TypeCastException
at java.lang.Class.getDeclaredMethods0(Native Method)
gildor
04/24/2019, 1:36 PMjanvladimirmostert
04/24/2019, 1:52 PMjanvladimirmostert
04/24/2019, 1:52 PMjanvladimirmostert
04/24/2019, 1:52 PMjanvladimirmostert
04/24/2019, 1:53 PMsourceSets.main {
java.srcDir("src/main/java")
withConvention(KotlinSourceSet::class) {
kotlin.srcDir("src/main/kotlin")
}
}
janvladimirmostert
04/24/2019, 2:16 PMgildor
04/24/2019, 2:46 PMgildor
04/24/2019, 2:47 PMjanvladimirmostert
04/24/2019, 3:27 PMtasks.withType<Jar>
generates the correct manifest, although i get a JNI error on startup.
Busy upgrading my gradle version now from 5.1 to 5.4 to see if that fixes it.gildor
04/24/2019, 3:34 PMI’ve removed the sourceSets, still not getting an executable jarWhich task are you use? To make execcutable jar with all dependencies you need application plugin + shadow plugin
janvladimirmostert
04/24/2019, 3:36 PMbuild.gradle.kts
with dependencies cut off to fit in here:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "za.co.convirt"
version = "1.2.0"
description = "App Build"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
application {
mainClassName = "AppBuildApi"
}
plugins {
val kotlinVersion = "1.3.30"
application
id("org.jetbrains.kotlin.plugin.noarg").version(kotlinVersion)
kotlin("jvm").version(kotlinVersion)
id("com.github.johnrengelman.shadow").version("5.0.0")
maven
}
repositories {
mavenLocal()
jcenter()
maven("<http://repo.maven.apache.org/maven2>")
}
tasks.withType<Jar> {
manifest {
attributes.put("Main-Class", application.mainClassName)
}
}
tasks.withType<KotlinCompile> {
incremental = true
kotlinOptions.jvmTarget = "1.8"
}
dependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))
compile(kotlin("test-junit")
janvladimirmostert
04/24/2019, 3:36 PMgildor
04/24/2019, 3:37 PMshadowJar
task to build executable shadow jargildor
04/24/2019, 3:37 PMjanvladimirmostert
04/24/2019, 3:39 PMgildor
04/24/2019, 3:43 PMjanvladimirmostert
04/24/2019, 3:44 PMExecution failed for task ':shadowJar'.
> shadow.org.apache.tools.zip.Zip64RequiredException: archive contains more than 65535 entries.
will probably need that zip64 setting heregildor
04/24/2019, 3:45 PMgildor
04/24/2019, 3:46 PMcompile(kotlin("test-junit")
instead of testCompile
? now you bundling all your test infrastructure with your appjanvladimirmostert
04/24/2019, 3:46 PMtasks.withType<ShadowJar> {
isZip64 = true
}
i've got a running app, thanks for the help Andrey!janvladimirmostert
04/24/2019, 3:46 PMgildor
04/24/2019, 3:47 PMimplementation
instead of compile
.
Compile configuration is deprecatedgildor
04/24/2019, 3:48 PMtasks.withType<ShadowJar> {Probably you can just use static accessor for this task:
tasks.shadowJar {}
janvladimirmostert
04/24/2019, 3:49 PMsnowe
04/24/2019, 3:49 PM.withType
the static accessor and .shadowJar
is dynamic accessor?gildor
04/24/2019, 3:51 PMsnowe
04/24/2019, 3:51 PMgildor
04/24/2019, 3:52 PMgildor
04/24/2019, 3:52 PMtasks.shadowJar
or tasks { shadowJar {} }
is type safe accessor generated by Kotlin DSL, so you can just access any task created by all applied pluginsgildor
04/24/2019, 3:53 PMsnowe
04/24/2019, 3:54 PMwithType
forces you to configure more than the type-safe version does. I use withType
everywhere I can, because IntelliJ is much faster at resolving the types.gildor
04/24/2019, 3:57 PMgildor
04/24/2019, 3:57 PMtasks.withType<ShadowJar>
will configure nothing if task of this type doesn’t exist in current modulegildor
04/24/2019, 3:58 PMIntelliJ is much faster at resolving the types.Not sure what you mean
gildor
04/24/2019, 4:00 PMgildor
04/24/2019, 4:01 PMtasks.withType
is somehow bad, but usually it’s not necessary to configure all tasks of this type, you need only one particular task, but also no need to know type of task, just namesnowe
04/24/2019, 4:03 PMhmm. I see what you mean now. In regards to intellij, it takes about 10-15 seconds for the appropriate type-safe accessor to pop up, while it only takes a second or two for the class name inwill configure nothing if task of this type doesn’t exist in current module (edited)tasks.withType<ShadowJar>
withType<>
to pop up.gildor
04/24/2019, 4:04 PMgildor
04/24/2019, 4:08 PMjanvladimirmostert
04/24/2019, 4:09 PMgildor
04/24/2019, 4:10 PMjanvladimirmostert
04/24/2019, 4:11 PMgildor
04/24/2019, 4:11 PM