Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Kotlin + Gradle = fun

92 views

Published on

Can Kotlin replace Groovy in Gradle?

Published in: Software
  • Be the first to comment

  • Be the first to like this

Kotlin + Gradle = fun

  1. 1. + =
  2. 2. + =
  3. 3. Gradle Сборщик, написанный на Groovy
  4. 4. Gradle 101 Init Configure Execute
  5. 5. Groovy Groovy — $hit для DSL
  6. 6. А на самом деле? git show --format=medium $(git rev- list HEAD | tail -n 1) commit 9ddae5a Author: Hans Dockter Date: Mon Mar 10 06:50:30 2008 +0000 create trunk directory git show --format=medium $(git rev- list HEAD | tail -n 1) commit 3e4dce3 Author: Andrey Breslav Date: Mon Nov 8 14:03:36 2010 +0300 test
  7. 7. Groovy DSL apply plugin: ‘java’ apply (plugin: ‘java’)
  8. 8. Groovy DSL configure(project) { … } configure(project, { … })
  9. 9. Groovy DSL apply (plugin: ‘java’) apply ([plugin: ‘java’])
  10. 10. Groovy DSL task wrapper (type: Wrapper) { version = ‘4.4’ } import o.g.a.t.w.Wrapper project.task( [type: Wrapper], ‘wrapper’, { version = ‘4.4’ } )
  11. 11. Изи? apply plugin: ‘application’ mainClass = ‘bkug.Seven’ distTar.enabled = false
  12. 12. ApplicationPlugin … project.getPluginManager().apply(JavaPlugin.class); project.getPluginManager().apply(DistributionPlugin.class); … addPluginConvention(); addRunTask(); addCreateScriptsTask(); …
  13. 13. Корень зла methodMissing(String name, def args)
  14. 14. Подловите меня! task wrapper (type: Wrapper) { gradleVersion = ‘4.4’ } apply plugin: ‘application’ mainClassName = ‘bkug.Seven’ distTar.enabled = false
  15. 15. Не надо шутить с Groovy + Сладенький − Слишком много магии − Слабая поддержка в IDE − Ошибки на рантайме
  16. 16. Kotlin fun
  17. 17. Kotlin Meets Gradle import org.gradle.api.plugins.* import org.gradle.script.lang.kotlin.* apply<ApplicationPlugin>() configure<ApplicationPluginConvention> { mainClassName = "bkug.Seven" } repositories { jcenter() } dependencies { "testCompile"("junit:junit:4.12") }
  18. 18. 1.5 года спустя
  19. 19. Kotlin DSL plugins { application kotlin("jvm") version ("1.1.51") id("org.jenkins-ci.jpi") version ("0.22.0") } apply<JUnitPlatformPlugin>()
  20. 20. Kotlin DSL application { mainClassName = "bkug.Seven" }
  21. 21. Kotlin DSL configure<JUnitPlatformExtension> { filters { tags { include("base") } } }
  22. 22. Kotlin DSL task<Wrapper>("wrapper") { gradleVersion = "4.1" distributionType = Wrapper.DistributionType.ALL }
  23. 23. Kotlin DSL tasks { "clean"(Delete::class) { delete(buildDir) } val wrapper by creating(Wrapper::class) { gradleVersion = "4.1" distributionType = Wrapper.DistributionType.ALL } }
  24. 24. Kotlin DSL val kotlinVersion by project dependencies { compile(kotlin("stdlib-jre8", "${kotlinVersion}")) }
  25. 25. Kotlin DSL apply { from("another.gradle.kts") }
  26. 26. Тяжёлый случай mavenDeployer { pom.project { withGroovyBuilder { "parent" { "groupId"("org.gradle") "artifactId"("kotlin- dsl") "version"("1.0") } } } }
  27. 27. Тяжёлый случай jenkinsPlugin { licenses = this.Licenses().apply { license(delegateClosureOf<JpiLicense> { setProperty("url", "http://www.wtfpl.net") }) } }
  28. 28. Как это работает? ./gradlew kotlinDslAccessorsSnapshot ./gradlew kotlinDslAccessorsReport
  29. 29. Как это работает? val Project.`application`: ApplicationPluginConvention get() = convention .getPluginByName<ApplicationPluginConvention>("application") fun Project.`application`( configure: ApplicationPluginConvention.() -> Unit ): Unit = configure(application)
  30. 30. Kotlin + Сладкий + Поддержка в IDE + Ошибки сразу − Не без магии
  31. 31. Groovy (не) умер ;( cloc --include-lang=Java,Kotlin,Groovy 01f906bf36a (March 2015) 9701 text files. 9400 unique files. 1487 files ignored. -------------------------------------------- Language files blank comment code -------------------------------------------- Groovy 3358 55627 49962 239691 Java 4940 51316 109756 206313 -------------------------------------------- SUM: 8298 106943 159718 446004 -------------------------------------------- cloc --include-lang=Java,Kotlin,Groovy master (Dec 2017) 14096 text files. 13650 unique files. 1854 files ignored. -------------------------------------------- Language files blank comment code -------------------------------------------- Groovy 5075 99084 70780 453953 Java 7248 74664 163400 324563 Kotlin 10 24 32 115 -------------------------------------------- SUM: 12333 173772 234212 778631 --------------------------------------------
  32. 32. Но это не важно! cd kotlin-dsl && cloc --include-lang=Java,Kotlin,Groovy . 441 text files. 326 unique files. 213 files ignored. ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Kotlin 233 3136 2560 9388 Groovy 14 32 41 131 Java 5 12 7 42 ------------------------------------------------------------------------------- SUM: 252 3180 2608 9561 -------------------------------------------------------------------------------
  33. 33. Спасибо! Q&A

×