Slide 1

Slide 1 text

Building Developer Tools with Kotlin and Gradle Breandan Considine GIDS 2017

Slide 2

Slide 2 text

Why Developer Tools? • Syntax manipulation • Typing completions • Static code analysis • UI/UX components • Language support • Framework support

Slide 3

Slide 3 text

Why Kotlin? • IntelliJ Platform / Eclipse integration • Java language / JVM interoperability • Simplifies framework interactions • Domain specific languages • Functional programming • Build tools integration

Slide 4

Slide 4 text

Why Gradle? • Comprehensive tooling support • Cross-platform IDE • Gradle tooling API • Language-native buildscripts • Vibrant plugin ecosystem • Gradlew is awesome!

Slide 5

Slide 5 text

public class Singleton { private Singleton() {} private static instance; public static Singleton getInstance() { if(instance == null) instance = new Singleton(); return instance; } public void doSomething() {} } 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: Singleton pattern: Java

Slide 6

Slide 6 text

Singleton.doSomething() Singleton pattern: Java Singleton.getInstance().doSomething();

Slide 7

Slide 7 text

Singleton.doSomething() object Singleton { fun doSomething() {} } Singleton pattern: Kotlin 1: 2: 3: Lazy Initialization

Slide 8

Slide 8 text

public class Singleton { private Singleton() {} private static instance; public static Singleton getInstance() { if(instance == null) instance = new Singleton(); return instance; } public void doSomething() {} } 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: Singleton pattern: Java

Slide 9

Slide 9 text

IntelliJ Platform SDK ActionManager.getInstance() .getAction("MyAction")… MyAction…

Slide 10

Slide 10 text

foo(bar) bar.foo() Extension functions

Slide 11

Slide 11 text

Extend any library class fun String.wordCount(s: String) { return s.split(" ") .filter { it.length > 3 } } "hello to the world".wordCount()

Slide 12

Slide 12 text

Extend any library class val File.extension: String get() = name.split(".").last() myFile.extension

Slide 13

Slide 13 text

Lazy Initialization val resource: Resource by lazy { println("Initializing…") configureResource() } println(resource) println(resource)

Slide 14

Slide 14 text

UI Configuration 1: val panel = panel { 2: noteRow("Login:") 3: row("Username:") { userField() } 4: row("Password:") { passwordField() } 5: row { 6: rememberCheckBox() 7: right { 8: link("Forgot?") { browse(forgot) } 9: } 10: } 11: noteRow("No account? $signupLink") 12: }

Slide 15

Slide 15 text

Gradle Script Kotlin (GSK) buildscript { repositories { gradleScriptKotlin() } dependencies { classpath(kotlinModule("gradle-plugin")) } }

Slide 16

Slide 16 text

Gradle Plugins plugins { id("org.jetbrains.intellij") version "0.2" } apply { plugin("org.jetbrains.intellij") plugin("kotlin") }

Slide 17

Slide 17 text

Gradle IntelliJ Plugin intellij { pluginName = "MyPlugin" updateSinceUntilBuild = false } group = "com.group" version = "1.0"

Slide 18

Slide 18 text

Gradle IntelliJ Plugin // Also useful for OSS contributors! intellij { runIde { args project.projectDir.path } downloadSources = false } // Run `./gradlew runIde` to open project

Slide 19

Slide 19 text

Links and Resources • Kotlin for Plugin Developers • Kotlin Gradle Plugin • Gradle Script Kotlin (GSK) • gradle-intellij-plugin • Kotlin Plugin for Eclipse • goomph: IDE as a build artifact • GIDS Plugin (from live code)