Lucas
12/23/2018, 9:41 PMbuild.gradle.kts
script into multiple short scripts that configure plugins and tasks? Do buildSrc
can help while https://github.com/gradle/kotlin-dsl/issues/424 and https://github.com/gradle/kotlin-dsl/issues/427 don't get fixed?snowe
12/23/2018, 9:42 PMCzar
12/23/2018, 9:46 PMplugins {}
. This approach really helped to properly structure the builds I've got on my hands. My build.gradle.kts files are now much leaner and utility functionality which earlier littered them is now much better looking as custom plugins in buildSrc.octylFractal
12/23/2018, 9:49 PMplugins {}
Czar
12/23/2018, 9:52 PMLucas
12/23/2018, 9:58 PMplugins {}
block and tasks configuration. Here is the file https://github.com/lucasvalenteds/responder/blob/main/responder-api/build.gradle.kts.octylFractal
12/23/2018, 10:05 PMbuildSrc
, include the kotlin-dsl
plugin in it, and wrap them in a plugin apply
.
you can apply the plugins using Project.apply
and add them to the buildSrc
classpath for versioning, which imo is a little cleaner (have your versions in one spot, usages in another)plugin
, it's a little overkillfun Project.shadowJarConfiguration() { ... }
and call thatLucas
12/23/2018, 10:23 PMbuildSrc/build.gradle.kts
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
id("org.jetbrains.kotlin.jvm") version "1.3.11"
id("com.github.johnrengelman.shadow") version "2.0.4"
}
repositories {
jcenter()
}
fun Project.kotlinConfiguration() {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}
fun Project.shadowJarConfiguration() {
tasks.withType<ShadowJar> {
baseName = rootProject.name
version = rootProject.version.toString()
classifier = ""
destinationDir = rootProject.projectDir
}
}
build.gradle.kts
// Leave it empty
octylFractal
12/23/2018, 10:24 PMsrc/main/kotlin/<pkg>
apply
in thembuild.gradle.kts
as:
// <relevant imports, IntelliJ can add them for you>
kotlinConfiguration()
shadowJarConfiguration()
Lucas
12/23/2018, 10:38 PM