A Builder's Intro to Kotlin

A presentation at Gradle Summit in June 2017 in Palo Alto, CA, USA by Jake Wharton

Slide 1

Slide 1

Jake Wharton A Builder's Intro to Kotlin

Slide 2

Slide 2

Kotlin?

Slide 3

Slide 3

Slide 4

Slide 4

Slide 5

Slide 5

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

Why Kotlin?

Slide 16

Slide 16

Plugin Author

Slide 17

Slide 17

Plugin Author Buildscript Author

Slide 18

Slide 18

Plugin Author Buildscript Author App Developer

Slide 19

Slide 19

val firstName: String = "Jake" 
 val lastName: String? = null

Slide 20

Slide 20

val firstName: String = "Jake" 
 val lastName: String? = null

Slide 21

Slide 21

val firstName: String = "Jake" 
 val lastName: String? = null

Slide 22

Slide 22

val firstName: String = "Jake" 
 val lastName: String? = null

Slide 23

Slide 23

val firstName: String = "Jake" 
 val lastName: String? = null

Slide 24

Slide 24

val firstName = "Jake" 
 val lastName: String? = null

Slide 25

Slide 25

class User { 


public String getName() { 


// ... 


} 


public void setName(String name) { 


// ... 


} 
 }

// ^^^ Java

Slide 26

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 )

Slide 27

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

Slide 28

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

Slide 29

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

Slide 30

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

Slide 31

Slide 31

class User { 


var name

"Jake" 
 }

// ^^^ Kotlin

Slide 32

Slide 32

class User { 


var name

"Jake" 
 }

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

  • user.getName());

Slide 33

Slide 33

class User { 


var name

"Jake" 
 }

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

  • user.getName());

Slide 34

Slide 34

class User { 


var name

"Jake" 
 }

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

  • user.getName());

user.setName( "Jane" );

Slide 35

Slide 35

class User { 


var name

"Jake" 
 }

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

  • user.getName());

user.setName( "Jane" );

Slide 36

Slide 36

val user = User()

Slide 37

Slide 37

val user = User() 
 user = User()

Slide 38

Slide 38

val user = User() 
 user = User() 



 var currentUser = User() 
 currentUser = User()

Slide 39

Slide 39

fun Date.isTuesday(): Boolean { 


return day

2 
 }

Slide 40

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." ) 
 }

Slide 41

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." ) 
 }

Slide 42

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)

Slide 43

Slide 43

val executor = Executors.newSingleThreadExecutor(); 
 executor. execute { B println ( "Background thread!" ) } X

Slide 44

Slide 44

val executor = Executors.newSingleThreadExecutor();

val foo = Foo() 
 executor. execute (foo::printIt)

class Foo {

fun printIt() { B

println(

"Background thread!" ) } X

}

Slide 45

Slide 45

val executor = Executors.newSingleThreadExecutor();

val foo = Foo() 
 executor. execute (foo::printIt)

class Foo {

fun printIt() { B

println(

"Background thread!" ) } X

}

Slide 46

Slide 46

fun < T

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


// ... 
 }

Slide 47

Slide 47

fun < T

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


// ... 
 }

Slide 48

Slide 48

fun < T

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


// ... 
 } A

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

Slide 49

Slide 49

fun < T

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


// ... 
 } A

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

Slide 50

Slide 50

fun < T

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


// ... 
 } A

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

Slide 51

Slide 51

fun < T

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


// ... 
 } A

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

Slide 52

Slide 52

fun < T

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


// ... 
 } A

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

Slide 53

Slide 53

fun < T

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


// ... 
 } A

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

val oddSet = items. filterTo(mutableListOf()) { it % 2 != 0 }

Slide 54

Slide 54

fun < T

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


// ... 
 } A

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

Slide 55

Slide 55

inline fun < T

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


// ... 
 } A

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

Slide 56

Slide 56

inline fun < T

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

val destination = mutableListOf < T

()

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

Slide 57

Slide 57

inline fun < T

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

val destination = mutableListOf < T

()

for (item in this ) {

if (predicate(item)) destination.add(item) } B

return destination } A

val items = listOf ( 1 , 2 , 3 ) val destination = mutableListOf <Int>() for (item in items ) {

if (item % 2 != 0 ) destination.add(item) } G

val odds = destination

filter

it

Slide 58

Slide 58

fun < T

List< T .filterIsInstance(c: Class< T ): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (c.isInstance(item)) destination.add(item)

}

return destination 
 } A

Slide 59

Slide 59

fun < T

List< T .filterIsInstance(c: Class< T ): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (c.isInstance(item)) destination.add(item) } G

return destination 
 } A

Slide 60

Slide 60

fun < T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (item in

T ) destination.add(item) } G

return destination 
 } A

c: Class<T> 


c.isInstance(
)

Slide 61

Slide 61

fun < T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (item in

T ) destination.add(item) } G

return destination 
 } A

Slide 62

Slide 62

inline fun < T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (item in

T ) destination.add(item) } G

return destination 
 } A

Slide 63

Slide 63

inline fun < reified T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (item in

T ) destination.add(item) } G

return destination 
 } A

Slide 64

Slide 64

inline fun < reified T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() for (item in this ) {

if (item in

T ) destination.add(item) } G

return destination 
 } A

Slide 65

Slide 65

inline fun < reified T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() 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 <Int>()

Slide 66

Slide 66

inline fun < reified T

List< T .filterIsInstance(): List< T { 


val destination = mutableListOf < T

() 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 <Int>()

ALOAD 7

item

INSTANCEOF java/lang/Integer IFEQ L8 ALOAD 5

destination

ALOAD 7

item

INVOKEINTERFACE java/util/Collection.add (Ljava/lang/Object;)Z

Slide 67

Slide 67

class User { D 


val name

"Jake" 
 } A

Slide 68

Slide 68

class User(name: String) { D 


val name = name 
 } A 


    "

Jake"

Slide 69

Slide 69

class User( val

name : String) { 
 } A

Slide 70

Slide 70

class User( val

name : String)

Slide 71

Slide 71

class User( val

name : String)

val jake = User( "Jake" ) println ( "Hello, $ jake !" )

Slide 72

Slide 72

class User( val

name : String)

val jake = User( "Jake" ) println ( "Hello, $ jake !" )

Hello, User@3a71f4dd !

Slide 73

Slide 73

data class User( val

name : String)

val jake = User( "Jake" ) println ( "Hello, $ jake !" )

Hello, User@3a71f4dd !

Slide 74

Slide 74

@3a71f4dd data class User( val

name : String)

val jake = User( "Jake" ) println ( "Hello, $ jake !" )

Hello, User(name=Jake) !

Slide 75

Slide 75

data class User( val

name : String)

val jake = User( "Jake" ) println ( "Hello, $ jake !" )

Hello, User(name=Jake) !

Slide 76

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() } }

Slide 77

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

Slide 78

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

Slide 79

Slide 79

val deleteByName by lazy {

db.createStatement( "DELETE FROM user WHERE name = ?" ) } C

Slide 80

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 " ) }

Slide 81

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<String>()

Slide 82

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<String>() val nameView by bindView <TextView>(R. id . name )

Slide 83

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<String>() val nameView by bindView <TextView>(R. id . name )

Slide 84

Slide 84

fun main( vararg args: String) = runBlocking<Unit> {

val jobs = List ( 100_000 ) {

launch(CommonPool) {

delay( 1000L )

print ( "." )

} }

jobs.forEach { it.join() } }

Slide 85

Slide 85

Plugin Author Buildscript Author App Developer

Slide 86

Slide 86

App Developer

Plugin Author

Buildscript Author

Slide 87

Slide 87

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

Slide 88

Slide 88

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

Slide 89

Slide 89

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

Slide 90

Slide 90

*.java *.kt

Slide 91

Slide 91

*.java *.kt kotlinc

Slide 92

Slide 92

*.java *.kt kotlinc

Slide 93

Slide 93

*.java *.kt kotlinc javac

Slide 94

Slide 94

*.java *.kt kotlinc javac

Slide 95

Slide 95

*.java *.kt kotlinc javac

Slide 96

Slide 96

kotlin-stdlib *.java *.kt kotlinc javac

Slide 97

Slide 97

kotlin-stdlib *.java *.kt kotlinc javac

Slide 98

Slide 98

kotlin-stdlib *.java *.kt kotlinc javac

project(':some-library')

Slide 99

Slide 99

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

Slide 100

Slide 100

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

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

Slide 101

Slide 101

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

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

apply plugin : 'kotlin2js '

Slide 102

Slide 102

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

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

apply plugin : 'kotlin2js'

apply plugin : 'konan'

Different classpath dependency

Slide 103

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

Slide 104

Slide 104

Plugin Author Buildscript Author App Developer

Slide 105

Slide 105

Buildscript Author

Plugin Author

App Developer

Slide 106

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

}

Slide 107

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

}

Slide 108

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

}

Slide 109

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

}

Slide 110

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

}

Slide 111

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

}

Slide 112

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

}

Slide 113

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

}

Slide 114

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' )

} }

}

Slide 115

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' )

} }

}

Slide 116

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' ) } 
 
 }

Slide 117

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

Slide 118

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

Slide 119

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

Slide 120

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

Slide 121

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

Slide 122

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

Slide 123

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

Slide 124

Slide 124

Slide 125

Slide 125

Slide 126

Slide 126

Plugin Author Buildscript Author App Developer

Slide 127

Slide 127

Plugin Author

Buildscript Author

App Developer

Slide 128

Slide 128

class My Plugin : Plugin<Project> {

override fun apply(project: Project) {

// ...

} B

} A

Slide 129

Slide 129

import org.gradle.kotlin.dsl.* class My Plugin : Plugin<Project> {

override fun apply(project: Project) {

// ...

} B

} A

Slide 130

Slide 130

kotlin-stdlib *.java *.kt kotlinc javac

Slide 131

Slide 131

kotlin-stdlib *.java *.kt kotlinc javac

apply plugin : 'your-gradle-plugin'

Slide 132

Slide 132

Slide 133

Slide 133

Slide 134

Slide 134

Slide 135

Slide 135

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