kotlin-based build scripts - doag.org · gradle build automation system written mostly in groovy...

23
Kotlin-based Build Scripts New Opportunities in Gradle 3.0 Tim Riemer

Upload: doque

Post on 02-Sep-2018

245 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Kotlin-based Build Scripts

New Opportunities in Gradle 3.0

Tim Riemer

Page 2: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

About meTim Riemer

Integration Architect @ FNT GmbH

Java since 20 years

More than 10 years for a living

@zordan_f

TimRiemer

Page 3: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1
Page 4: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

GradleBuild Automation System

Written mostly in Groovy

Groovy DSL

Initial Release in 2007

Current Version 3.4.1

Page 5: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Since 3.0Daemon enabled by default (3.0)

Composite Builds (3.1)

Incremental Builds Improvements

Compile Avoidance (3.4)

Java-Library plugin (3.4)

Page 6: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1
Page 7: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

KotlinStatically-typed

Based on the JVM

Java interoperability

Developed by Jetbrains since 2010

First Version 2012

Current Release 1.1.1

Page 8: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

KotlinNull-pointer safety

Extension functions

Infix notation

Scripting (.kts)

Type-safe DSLs

Good IDE support

Page 9: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1
Page 10: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Gradle Script KotlinAnnounced in May 2016

Current Release 0.8.0

Page 11: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Why?Groovy DSL not designed for performance

Tooling not ideal

Build Scripts that are

… expressive

… declarative and concise

… fluid and readable

… highly performant

Page 12: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

GoalsEase of migration

Preserve existing Gradle plugins

Use idiomatic Kotlin to write Scripts and Plugins

Page 13: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

ChallengesDynamic concepts in statically-typed language

Only change syntax with good reason

Existing Gradle APIs with Closure and Action<T>

Page 14: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Extension Functions

fun DependencyHandler.compile(dependencyNotation: Any

): Dependency = add("compile", dependencyNotation)

Page 15: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Lambda with receiver

inline fun <T : ModuleDependency> DependencyHandler.add( configuration: String, dependency: T, dependencyConfiguration: T.() -> Unit): T = dependency.apply { dependencyConfiguration() add(configuration, this) }

Page 16: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Delegated Properties

// task into scope by nameval clean by tasks

// task into scope by name and typeval jar: Jar by tasks

Page 17: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

AccessorsJust-in-time

Ahead-of-time

Ad-hoc

Page 18: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

DEMO

Page 19: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

IDE SupportIntelliJ IDEA (Kotlin Plugin)

Eclipse (Buildship 2 and Kotlin Plugin)

Netbeans (Kotlin Plugin)

Page 20: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

What’s coming next?Release 1.0

Independent Update mechanism

Compilation speed / performance

Stable DSL (esp. plugins{})

Custom receiver vs Closure / Action<T>

Auto detection of build.gradle.kts

.kts version of settings.gradle?

Page 21: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Further InformationGithub

https://github.com/gradle/gradle-script-kotlin

Gradle meets Kotlinhttps://blog.gradle.org/kotlin-meets-gradle

Kotlin Slackhttp://slack.kotlinlang.org/

Blogpost from Cédric Champeauhttp://melix.github.io/blog/2016/05/gradle-kotlin.html

Page 22: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Questions?

Page 23: Kotlin-based Build Scripts - doag.org · Gradle Build Automation System Written mostly in Groovy Groovy DSL Initial Release in 2007 Current Version 3.4.1

Thank you!