Gradle Kotlin DSL syntax

After a bit of a fight, got my build file functional:

`import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin(“jvm”) version “1.2.51”
id(“com.github.johnrengelman.shadow”) version “2.0.4”
}

group = “xxx.yyy”
version = “1.0-SNAPSHOT”

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin(“stdlib-jdk8”))
}

tasks.withType {
kotlinOptions.jvmTarget = “1.8”
}

tasks.withType {

baseName = "app"
classifier = "inajar"
version = "9"


manifest.attributes.apply {
    put("Implementation-Title", "Gradle Jar File Example")
    //put("Implementation-Version" version)
    put("Main-Class", "HelloKotlinWorld.App")
}

}

`

Now, the question is: what does it mean and how does it work?

In particular, this syntax:

tasks.withType<ShadowJar>

means what? It’s invoking the withType method of a task instance? I’m not familiar with the diamond syntax in this context. What does the diamond operator, less than and greater than, do?

I have other questions, but that’s my primary confusion. Obviously, learning this DSL.

This is the Kotlin syntax for reified type parameters.

Calling withType<ShadowJar> { ... } in Kotlin is equivalent to the Groovy withType(ShadowJar) { ... }.

1 Like

LOL. Thanks. I’ll re-read that link more than a few times, but at present it’s all greek to me.

I subscribed to some Kotlin blogs, but if there’s a book you can recommend that would go a long way.

This one is really good https://www.manning.com/books/kotlin-in-action