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

"Gradle Magic" from Sergey Kozyrev

"Gradle Magic" from Sergey Kozyrev

We will start with groovy walk-through, then go to Gradle for Java, Gradle for Android SDK and Android NDK. Finally, we will learn how to make Your own Gradle plugin on live demo!

uaMobiTech

July 29, 2016
Tweet

More Decks by uaMobiTech

Other Decks in Programming

Transcript

  1. Agenda • Why need gradle? • Syntax magic • One

    task “to rule them all”! • Plugins to encapsulate anything • Java plugin • Android builds • Demo “Create Your own plugin”
  2. Why build tools? • hmm… so what do I need

    to do to ship it? подумаем, что нам нужно сделать, чтобы получить билд? сгенерил апк и отправил? ок, а если бы не было этой волшебной кнопки? заказчик просит релейную сборку, скопировать все апи-ключи… ок, обновилась библиотека, надо ее переподложить, опус, у нее тоже поменялись зависимости, ок едем дальше… что? нам нужна платная и бесплатная версия? разные апк??? нам нужно такое же приложение, но с другими картинками? сколько каждое из них (2х2х2) весит? сколько методов? так отбрасываем часть функционала - надо чтобы кто-то поудалял ненужные ресурсы, кто-то посчитал методы, и надо еще написать систему которая засолвит Х
  3. Why gradle? • We need easy to configure and use,

    robust, agile… • Do we really need to reinvent it?
  4. How to install • Download and add some vars •

    homebrew • SdkMan • or … simply use gradle wrapper !
  5. Build scripts declarative! You say WHAT You want *hint: If

    You want to change HOW - create a plugin!
  6. • support of Java, Scala, Groovy • optional typing (def

    foo = 6.5) • lists (def myList = ["Gradle", "Groovy", "Android"]) • closures (def printItem = {item -> println "List item: $item"}) • delegates (def greetingClosure = {printGreeting()}) Syntax
  7. • support of Java, Scala, Groovy • optional typing def

    foo = 6.5 • lists def myList = ["Gradle", "Groovy", "Android"] • closures def printItem = {item -> println "List item: $item"} • delegates def greetingClosure = {printGreeting()} Syntax
  8. Parenthesis magic When the last parameter of a method is

    a closure, you can place the closure after the method call
  9. Task to rule them all • Function, can be entry

    point • Task dependency robustness • dependsOn • finalizedBy • mustRunAfter • dependsOn tasks.matching(task -> task.name.startsWith("pattern")) hard-to-impossible in other build tool
  10. Typed tasks • Tasks may have type • doLast, doFirst

    - adHoc tasks • Typed tasks "task copyFiles(type: Copy)” • Copy, Zip, Delete (easy configurable closures like from, into, include etc.)
  11. Plugins • define tasks and task types, • configure repositories,

    • apply other plugins, • extend gradle dsl Plugin can:
  12. apply plugin java • clean • check • assemble •

    lots of very smart pre-configurations • gradle jar -> does everything for You :)
  13. No more juggling jars • download dependency once even for

    different projects - local cache • repositories mavenCentral(), jCenter(), local • http/https/sftp/file_based • dependencies compile by name, groovy-style name, files collection, fileTree (for *.inc filtering)
  14. Dependencies • gradle dependencies -> shows all dependencies including transitive

    • gradle dependencyInsight -> for deep dive into one given dependency, shows conflicts and resolving • dependencies configurations: compile, testCompile, testRuntime
  15. Tests • Unit tests and Integration tests • different source

    dirs • different dependency configs • different tasks • test reports out of the box
  16. Android build system Android Studio delegates to Gradle .gradle folder

    stores info for incremental builds apply plugin ‘android’
  17. Life is easy because of Gradle • Build Types •

    Flavors • Dependencies on per variant basis • App signing • Merging resources
  18. We need to go deeper • Some tasks (aka compileFreeDebug)

    are generated in time of configuration • applicationVariant.all -> collection of build variants that not yet exist!
  19. Lots of cool features • multi project build - by

    default (settings.gradle to specify projects) • jar and aar for libs with resources • unit and AndroidTest go with same build variants naming rules • multidex support - multiDexEnabled true • proguard|minifyEnabled|shrinkResources
  20. Ready to go plugins for everything • Optimize images •

    Measure metrics • Layouts generating • Wearables and auto • Code generating • Plugin publishing plugin :)