Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Builder's Intro to Kotlin (Gradle Summit 2017)

A Builder's Intro to Kotlin (Gradle Summit 2017)

Kotlin's popularity has been exploding in the past year. From last year's announcement that Gradle would support it as a build language, to its adoption on large platforms like Android and Spring, to its general applicability for writing IDE and build system plugins, it's hard to find an area that isn't adopting the language in some form.

This talk will be an introduction to the language in the context of Gradle. After covering the language syntax and features and their benefits, we'll look at why it's great for authoring Gradle plugins. Finally, we'll set the stage for Gradle's Kotlin build script support for which there are other full talks at the conference.

Video: https://youtu.be/UAec6OpJiA8

Jake Wharton
PRO

June 22, 2017
Tweet

More Decks by Jake Wharton

Other Decks in Programming

Transcript

  1. Jake Wharton
    A Builder's Intro
    to Kotlin

    View Slide

  2. Kotlin?

    View Slide

  3. View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. Why Kotlin?

    View Slide

  16. Plugin Author

    View Slide

  17. Plugin Author Buildscript Author

    View Slide

  18. Plugin Author Buildscript Author App Developer

    View Slide

  19. val firstName: String = "Jake"

    val lastName: String? = null

    View Slide

  20. val firstName: String = "Jake"

    val lastName: String? = null

    View Slide

  21. val firstName: String = "Jake"

    val lastName: String? = null

    View Slide

  22. val firstName: String = "Jake"

    val lastName: String? = null

    View Slide

  23. val firstName: String = "Jake"

    val lastName: String? = null

    View Slide

  24. val firstName = "Jake"

    val lastName: String? = null

    View Slide

  25. class User {

    public String getName() {

    // ...

    }

    public void setName(String name) {

    // ...

    }

    }
    // ^^^ Java

    View Slide

  26. class User {

    public String getName() {

    // ...

    }X

    public void setName(String name) {

    // ...

    }Y

    }Z
    // ^^^ Java vvv Kotlin
    val user = User()

    println("Name is " + user.name)

    View Slide

  27. class User {

    public String getName() {

    // ...

    }X

    public void setName(String name) {

    // ...

    }Y

    }Z
    // ^^^ Java vvv Kotlin
    val user = User()

    println("Name is " + user.name)X

    View Slide

  28. class User {

    public String getName() {

    // ...

    }X

    public void setName(String name) {

    // ...

    }Y

    }Z
    // ^^^ Java vvv Kotlin
    val user = User()

    println("Name is ${user.name}")X

    View Slide

  29. class User {

    public String getName() {

    // ...

    }X

    public void setName(String name) {

    // ...

    }Y

    }Z
    // ^^^ Java vvv Kotlin
    val user = User()

    println("Name is $user")X

    View Slide

  30. class User {

    public String getName() {

    // ...

    }X

    public void setName(String name) {

    // ...

    }Y

    }Z
    // ^^^ Java vvv Kotlin
    val user = User()

    println("Name is $user")X

    View Slide

  31. class User {

    var name = "Jake"

    }
    // ^^^ Kotlin

    View Slide

  32. class User {

    var name = "Jake"

    }
    // ^^^ Kotlin vvv Java
    User user = new User();
    System.out.println("Name is " + user.getName());

    View Slide

  33. class User {

    var name = "Jake"

    }
    // ^^^ Kotlin vvv Java
    User user = new User();
    System.out.println("Name is " + user.getName());

    View Slide

  34. class User {

    var name = "Jake"

    }
    // ^^^ Kotlin vvv Java
    User user = new User();
    System.out.println("Name is " + user.getName());
    user.setName("Jane");

    View Slide

  35. class User {

    var name = "Jake"

    }
    // ^^^ Kotlin vvv Java
    User user = new User();
    System.out.println("Name is " + user.getName());
    user.setName("Jane");

    View Slide

  36. val user = User()

    View Slide

  37. val user = User()

    user = User()

    View Slide

  38. val user = User()

    user = User()


    var currentUser = User()

    currentUser = User()

    View Slide

  39. fun Date.isTuesday(): Boolean {

    return day == 2

    }

    View Slide

  40. fun Date.isTuesday(): Boolean {

    return day == 2

    }
    val epoch = Date(1970, 0, 0)

    if (epoch.isTuesday()) {

    println("The epoch was a Tuesday.")

    } else {

    println("The epoch was not a Tuesday.")

    }

    View Slide

  41. fun Date.isTuesday(): Boolean {

    return day == 2

    }
    val epoch = Date(1970, 0, 0)

    if (epoch.isTuesday()) {

    println("The epoch was a Tuesday.")

    } else {

    println("The epoch was not a Tuesday.")

    }

    View Slide

  42. fun Date.isTuesday(): Boolean {

    return day == 2

    }
    val epoch = Date(1970, 0, 0)

    if (epoch.isTuesday()) {

    println("The epoch was a Tuesday.")

    } else {

    println("The epoch was not a Tuesday.")

    }
    // ^^^ Kotlin vvv Java
    DateKt.isTuesday(date)

    View Slide

  43. val executor = Executors.newSingleThreadExecutor();

    executor.execute {Bprintln("Background thread!") }X

    View Slide

  44. val executor = Executors.newSingleThreadExecutor();
    val foo = Foo()

    executor.execute(foo::printIt)
    class Foo {
    fun printIt() {B
    println("Background thread!")
    }X
    }

    View Slide

  45. val executor = Executors.newSingleThreadExecutor();
    val foo = Foo()

    executor.execute(foo::printIt)
    class Foo {
    fun printIt() {B
    println("Background thread!")
    }X
    }

    View Slide

  46. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }

    View Slide

  47. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }

    View Slide

  48. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter({ item -> item % 2 != 0 })B

    View Slide

  49. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter({ item -> item % 2 != 0 })B

    View Slide

  50. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter({ it % 2 != 0 })B

    View Slide

  51. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter()B{ it % 2 != 0 }

    View Slide

  52. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter { it % 2 != 0 }

    View Slide

  53. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val oddList = items.filter { it % 2 != 0 }
    val oddSet = items.filterTo(mutableListOf()) { it % 2 != 0 }

    View Slide

  54. fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter { it % 2 != 0 }

    View Slide

  55. inline fun List.filter(predicate: (T) -> Boolean): List {

    // ...

    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter { it % 2 != 0 }

    View Slide

  56. inline fun List.filter(predicate: (T) -> Boolean): List {
    val destination = mutableListOf()
    for (item in this) {
    if (predicate(item)) destination.add(item)
    }B
    return destination
    }A
    val items = listOf(1, 2, 3)
    val odds = items.filter { it % 2 != 0 }
    val destination = mutableListOf< >()
    for (item in ) {
    if ( item ) destination.add(item)
    }G
    destination

    View Slide

  57. inline fun List.filter(predicate: (T) -> Boolean): List {
    val destination = mutableListOf()
    for (item in this) {
    if (predicate(item)) destination.add(item)
    }B
    return destination
    }A
    val items = listOf(1, 2, 3)
    val destination = mutableListOf()
    for (item in items) {
    if (item % 2 != 0) destination.add(item)
    }G
    val odds = destination
    filter it

    View Slide

  58. fun List.filterIsInstance(c: Class): List {

    val destination = mutableListOf()
    for (item in this) {
    if (c.isInstance(item)) destination.add(item)
    }
    return destination

    }A

    View Slide

  59. fun List.filterIsInstance(c: Class): List {

    val destination = mutableListOf()
    for (item in this) {
    if (c.isInstance(item)) destination.add(item)
    }G
    return destination

    }A

    View Slide

  60. fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }G
    return destination

    }A
    c: Class

    c.isInstance( )

    View Slide

  61. fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }G
    return destination

    }A

    View Slide

  62. inline fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }G
    return destination

    }A

    View Slide

  63. inline fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }G
    return destination

    }A

    View Slide

  64. inline fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }G
    return destination

    }A

    View Slide

  65. inline fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }
    return destination

    }A
    val list = listOf(1, 2f, 3, 4f)
    val ints = list.filterIsInstance()

    View Slide

  66. inline fun List.filterIsInstance(): List {

    val destination = mutableListOf()
    for (item in this) {
    if (item in T) destination.add(item)
    }
    return destination

    }A
    val list = listOf(1, 2f, 3, 4f)
    val ints = list.filterIsInstance()
    ALOAD 7 # item
    INSTANCEOF java/lang/Integer
    IFEQ L8
    ALOAD 5 # destination
    ALOAD 7 # item
    INVOKEINTERFACE java/util/Collection.add (Ljava/lang/Object;)Z

    View Slide

  67. class User {D

    val name = "Jake"

    }A

    View Slide

  68. class User(name: String) {D

    val name = name

    }A

    "Jake"

    View Slide

  69. class User(val name: String) {

    }A

    View Slide

  70. class User(val name: String)

    View Slide

  71. class User(val name: String)
    val jake = User("Jake")
    println("Hello, $jake!")

    View Slide

  72. class User(val name: String)
    val jake = User("Jake")
    println("Hello, $jake!")
    Hello, User@3a71f4dd!

    View Slide

  73. data class User(val name: String)
    val jake = User("Jake")
    println("Hello, $jake!")
    Hello, User@3a71f4dd!

    View Slide

  74. @3a71f4dd
    data class User(val name: String)
    val jake = User("Jake")
    println("Hello, $jake!")
    Hello, User(name=Jake)!

    View Slide

  75. data class User(val name: String)
    val jake = User("Jake")
    println("Hello, $jake!")
    Hello, User(name=Jake)!

    View Slide

  76. class UserPersisence(db: SqlDatabase) {
    private val deleteByName
    = db.createStatement("DELETE FROM user WHERE name = ?")
    fun delete(name: String) {
    deleteByName.bind(1, name)
    deleteByName.execute()
    }
    }

    View Slide

  77. class UserPersisence(db: SqlDatabase) {
    private val deleteByName
    = db.createStatement("DELETE FROM user WHERE name = ?")
    fun delete(name: String) {
    deleteByName.bind(1, name)
    deleteByName.execute()
    }B
    }A

    View Slide

  78. class UserPersisence(db: SqlDatabase) {
    private val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C
    fun delete(name: String) {
    deleteByName.bind(1, name)
    deleteByName.execute()
    }B
    }A

    View Slide

  79. val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C

    View Slide

  80. val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C
    var name by Delegates.observable("Jane") { prop, old, new ->
    println("Name changed from $old to $new")
    }

    View Slide

  81. val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C
    var name by Delegates.observable("Jane") { prop, old, new ->
    println("Name changed from $old to $new")
    }
    var address by Delegates.notNull()

    View Slide

  82. val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C
    var name by Delegates.observable("Jane") { prop, old, new ->
    println("Name changed from $old to $new")
    }
    var address by Delegates.notNull()
    val nameView by bindView(R.id.name)

    View Slide

  83. val deleteByName by lazy {
    db.createStatement("DELETE FROM user WHERE name = ?")
    }C
    var name by Delegates.observable("Jane") { prop, old, new ->
    println("Name changed from $old to $new")
    }
    var address by Delegates.notNull()
    val nameView by bindView(R.id.name)

    View Slide

  84. fun main(vararg args: String) = runBlocking {
    val jobs = List(100_000) {
    launch(CommonPool) {
    delay(1000L)
    print(".")
    }
    }
    jobs.forEach { it.join() }
    }

    View Slide

  85. Plugin Author Buildscript Author App Developer

    View Slide

  86. Plugin Author Buildscript Author
    App Developer

    View Slide

  87. apply plugin: 'org.jetbrains.kotlin.jvm'

    View Slide

  88. apply plugin: 'org.jetbrains.kotlin.jvm'
    src/
    main/
    java/
    Fizz.java
    Buzz.java

    View Slide

  89. apply plugin: 'org.jetbrains.kotlin.jvm'
    src/
    main/
    java/
    Fizz.java
    Buzz.kt

    View Slide

  90. *.java
    *.kt

    View Slide

  91. *.java
    *.kt
    kotlinc

    View Slide

  92. *.java
    *.kt
    kotlinc

    View Slide

  93. *.java
    *.kt
    kotlinc javac

    View Slide

  94. *.java
    *.kt
    kotlinc javac

    View Slide

  95. *.java
    *.kt
    kotlinc javac

    View Slide

  96. kotlin-stdlib
    *.java
    *.kt
    kotlinc javac

    View Slide

  97. kotlin-stdlib
    *.java
    *.kt
    kotlinc javac

    View Slide

  98. kotlin-stdlib
    *.java
    *.kt
    kotlinc javac
    project(':some-library')

    View Slide

  99. apply plugin: 'org.jetbrains.kotlin.jvm'

    View Slide

  100. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.android'

    View Slide

  101. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.android'
    apply plugin: 'kotlin2js'

    View Slide

  102. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.android'
    apply plugin: 'kotlin2js'
    apply plugin: 'konan' # Different classpath dependency

    View Slide

  103. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.android'
    apply plugin: 'kotlin2js'
    apply plugin: 'konan' # Different classpath dependency
    or
    apply plugin: 'org.jetbrains.kotlin.platform.common'
    apply plugin: 'org.jetbrains.kotlin.platform.jvm'
    apply plugin: 'org.jetbrains.kotlin.platform.js'
    apply plugin: 'konan' # Different classpath dependency

    View Slide

  104. Plugin Author Buildscript Author App Developer

    View Slide

  105. Plugin Author
    Buildscript Author
    App Developer

    View Slide

  106. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  107. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  108. apply(plugin: 'org.jetbrains.kotlin.jvm')X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  109. apply(singletonMap('plugin', 'org.jetbrains.kotlin.jvm'))X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  110. apply(singletonMap('plugin', 'org.jetbrains.kotlin.jvm'))X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  111. apply(singletonMap('plugin', 'org.jetbrains.kotlin.jvm'))X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  112. apply(singletonMap('plugin', 'org.jetbrains.kotlin.jvm'))X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile(deps.javaPoet)
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  113. apply(singletonMap('plugin', 'org.jetbrains.kotlin.jvm'))X
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile(deps.javaPoet)
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }

    View Slide

  114. android {
    // ...
    testOptions {
    unitTests.all {
    systemProperty('robolectric.dependency.repo.id', 'example-nexus')
    systemProperty('robolectric.dependency.repo.url',
    'https://nexus.example.com/content/groups/public')
    }
    }
    }

    View Slide

  115. android {
    // ...
    testOptions {
    unitTests.all {
    systemProperty('robolectric.dependency.repo.id', 'example-nexus')
    systemProperty('robolectric.dependency.repo.url',
    'https://nexus.example.com/content/groups/public')
    }
    }
    }

    View Slide

  116. android {
    // ...
    testOptions {
    unitTests.all {
    systemProperty('robolectric.dependency.repo.id', 'example-nexus')
    systemProperty('robolectric.dependency.repo.url',
    'https://nexus.example.com/content/groups/public') }


    }

    View Slide

  117. apply plugin: 'org.jetbrains.kotlin.jvm'
    apply plugin: 'org.jetbrains.kotlin.kapt'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    dependencies {
    compile deps.kotlin.stdLibJre8
    compile deps.javaPoet
    compile deps.autoCommon
    compileOnly deps.autoService
    kapt deps.autoService
    testCompile deps.junit
    testCompile deps.truth
    testCompile deps.compileTesting
    }A
    java
    build.gradle

    View Slide

  118. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  119. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  120. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  121. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  122. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  123. apply {
    plugin('org.jetbrains.kotlin.jvm')
    plugin('org.jetbrains.kotlin.kapt')
    }
    java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
    compile(deps.kotlin.stdLibJre8)
    compile(deps.javaPoet)
    compile(deps.autoCommon)
    compileOnly(deps.autoService)
    kapt(deps.autoService)
    testCompile(deps.junit)
    testCompile(deps.truth)
    testCompile(deps.compileTesting)
    }A
    build.gradle.kts

    View Slide

  124. View Slide

  125. View Slide

  126. Plugin Author Buildscript Author App Developer

    View Slide

  127. Plugin Author
    Buildscript Author App Developer

    View Slide

  128. class MyPlugin : Plugin {
    override fun apply(project: Project) {
    // ...
    }B
    }A

    View Slide

  129. import org.gradle.kotlin.dsl.*
    class MyPlugin : Plugin {
    override fun apply(project: Project) {
    // ...
    }B
    }A

    View Slide

  130. kotlin-stdlib
    *.java
    *.kt
    kotlinc javac

    View Slide

  131. kotlin-stdlib
    *.java
    *.kt
    kotlinc javac
    apply plugin: 'your-gradle-plugin'

    View Slide

  132. View Slide

  133. View Slide

  134. +

    View Slide

  135. jakewharton
    jakewharton
    jakewharton
    twitter.com/
    github.com/
    .com
    A Builder's Intro
    to Kotlin

    View Slide