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.

Gradle in 45min

1,333 views

Published on

An introduction to Gradle for JVM people. Describes the basics of Groovy & the Gradle DSL. Shows projects in various JVM languages.

Published in: Software
  • https://www.slideshare.net/xvier3453/android-studio-feature In today’s Era data security is one of the major concerns while transferring the data through wireless media.Due to the popularity of computer and Internet technology, network communication has penetrated into all aspects of society. Information security issues get more and more attention. Data encryption is the core in data confidentiality, integrity, effectiveness, and network security [1]. There are different algorithm and protocols available to address this issue. Encryption is the one of the best and highly used technology to secure the data. Encryption is the process of encoding a message or information in such a way that only authorized parties can access it. There are many Encryption algorithms available to encrypt the data. Symmetric key algorithms and Asymmetric key algorithms are two types of an encryption algorithm. In Symmetric key algorithms, both sender and recipient use the same private key to encrypt and decrypt the data. In another hand, Asymmetric key algorithms use different but related keys to encrypt and decrypt the message.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The presentation is clear and complete !
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Gradle in 45min

  1. 1. GRADLE IN 45MIN Schalk Cronjé
  2. 2. ABOUT ME Email: Twitter / Ello : @ysb33r ysb33r@gmail.com Gradle plugins authored/contributed to: VFS, Asciidoctor, JRuby family (base, jar, war etc.), GnuMake, Doxygen
  3. 3. GET YOUR DAILY GRADLE DOSE @DailyGradle #gradleTip
  4. 4. GRADLE A next generation build-and-deploy pipeline tool
  5. 5. MOST TRIVIAL JAVA PROJECT apply plugin: 'java' Will look for sources under src/main/java
  6. 6. JAVA PROJECT repositories { jcenter() } apply plugin : 'java' dependencies { testCompile 'junit:junit:4.1' }
  7. 7. GRADLE DEPENDENCY MANAGEMENT Easy to use Flexible to configure for exceptions Uses dependencies closure First word on line is usually name of a configuration. Configurations are usually supplied by plugins. Dependencies are downloaded from repositories Maven coordinates are used as format
  8. 8. GRADLE REPOSITORIES Specified within a repositories closure Processed in listed order to look for dependencies jcenter() preferred open-source repo. mavenLocal(), mavenCentral(), maven {} Ivy repositories via ivy {} Flat-directory repositories via flatDir
  9. 9. GRADLE REPOSITORIES repositories { jcenter() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } repositories { ivy { url 'file://path/to/repo' layout 'pattern', { artifact '[module]/[revision]/[artifact](.[ext])' ivy '[module]/[revision]/ivy.xml' } } }
  10. 10. GRADLE DSL Underlying language is Groovy You don’t need to be a Groovy expert to be a Gradle power user Groovy doesn’t need ; in most cases Groovy does more with less punctuation, making it an ideal choice for a DSL In most cases lines that do not end on an operator is considered a completed statement.
  11. 11. GROOVY VS JAVA In Groovy: All class members are public by default No need to create getters/setters for public fields Both static & dynamic typing supported def means Object
  12. 12. CALLING METHODS class Foo { void bar( def a,def b ) {} } def foo = new Foo() foo.bar( '123',456 ) foo.bar '123', 456 foo.with { bar '123', 456 }
  13. 13. CALLING METHODS WITH CLOSURES class Foo { void bar( def a,Closure b ) {} } def foo = new Foo() foo.bar( '123',{ println it } ) foo.bar ('123') { println it } foo.bar '123', { println it }
  14. 14. MAPS IN GROOVY Hashmaps in Groovy are simple to use def myMap = [ plugin : 'java' ] Maps are easy to pass inline to functions project.apply( plugin : 'java' ) Which in Gradle can become apply plugin : 'java'
  15. 15. LISTS IN GROOVY Lists in Groovy are simple too def myList = [ 'clone', ''http://github.com/ysb33r/GradleLectures' ] This makes it possible for Gradle to do args 'clone', 'http://github.com/ysb33r/GradleLectures'
  16. 16. CLOSURE DELEGATION IN GROOVY When a symbol cannot be resolved within a closure, Groovy will look elsewhere In Groovy speak this is called a Delegate. This can be programmatically controlled via the Closure.delegate property.
  17. 17. CLOSURE DELEGATION IN GROOVY class Foo { def target } class Bar { Foo foo = new Foo() void doSomething( Closure c ) { c.delegate = foo c() } } Bar bar = new Bar() bar.doSomething { target = 10 }
  18. 18. MORE CLOSURE MAGIC If a Groovy class has a method 'call(Closure)`, the object can be passed a closure directly. class Foo { def call( Closure c) { /* ... */ } } Foo foo = new Foo() foo { println 'Hello, world' } // This avoids ugly syntax foo.call({ println 'Hello, world' })
  19. 19. CLOSURE DELEGATION IN GRADLE In most cases the delegation will be entity the closure is passed to. Will also look at the Project and ext objects. The Closure.delegate property allows plugin writers ability to create beautiful DSLs task runSomething(type : Exec ) { cmdline 'git' } is roughly the equivalent of ExecTask runSomething = new ExecTask() runSomething.cmdline( 'git' )
  20. 20. GRADLE TASKS Can be based upon a task type task runSomething ( type : Exec ) { command 'git' args 'clone', 'https://bitbucket.com/ysb33r/GradleWorkshop' } Can be free-form task hellowWorld << { println 'Hello, world' }
  21. 21. GRADLE TASKS : CONFIGURATION VS ACTION Use of << {} adds action to be executed Tasks supplied by plugin will have default actions Use of {} configures a task
  22. 22. BUILDSCRIPT The buildscript closure is special It tells Gradle what to load into the classpath before evaluating the script itself. It also tells it where to look for those dependencies. Even though Gradle 2.1 has added a new way of adding external plugins, buildscript are much more flexible.
  23. 23. EXTENSIONS Extensions are global configuration blocks added by plugins. Example: The jruby-gradle-base plugin will add a jruby block. apply plugin: 'com.github.jruby-gradle.base' jruby { defaultVersion = '1.7.11' }
  24. 24. GRADLE COMMAND-LINE gradle -v gradle -h gradle tasks gradle tasks --info
  25. 25. GRADLE WRAPPER Use wrapper where possible: Eliminates need to install Gradle in order to build project Leads to more reproducible builds gradle wrapper --wrapper-version 2.12 ./gradlew tasks
  26. 26. EXECUTING TASKS ./gradlew <taskName1> <taskName2> ... ./gradlew build
  27. 27. DEPENDENCIES Examine dependencies involved with various configurations ./gradlew dependencies
  28. 28. SUPPORT FOR OTHER JVM LANGUAGES
  29. 29. GROOVY PROJECT repositories { jcenter() } apply plugin : 'groovy' dependencies { compile 'org.codehaus.groovy:groovy-all:2.4.3' testCompile ('org.spockframework:spock-core:1.0-groovy-2.4') { exclude module : 'groovy-all' } }
  30. 30. SCALA PROJECT repositories { jcenter() } apply plugin : 'scala' dependencies { compile 'org.scala-lang:scala-library:2.11.8' }
  31. 31. BUILDING KOTLIN plugins { id "com.zoltu.kotlin" version "1.0.1" } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.1-1" }
  32. 32. RUNNING JRUBY plugins { id 'com.github.jruby-gradle.base' version '1.2.1' } import com.github.jrubygradle.JRubyExec dependencies { jrubyExec "rubygems:colorize:0.7.7" } task printSomePrettyOutputPlease(type: JRubyExec) { description "Execute our nice local print-script.rb" script "${projectDir}/print-script.rb" } (Example from JRuby-Gradle project)
  33. 33. OTHER LANGUAGES C++ / C / ASM / Resources (built-in) Clojure (plugin) Frege (plugin) Golang (plugin) Gosu (plugin) Mirah (plugin in progress)
  34. 34. SUPPORT FOR OTHER BUILDSYSTEMS ANT (built-in) GNU Make MSBuild / xBuild Grunt, Gulp Anything else cra able via Exec or JavaExec task
  35. 35. BUILDING DOCUMENTATION Javadoc, Groovydoc, Scaladoc (built-in) Doxygen (C, C++) (plugin) Markdown (plugin) Asciidoctor (plugin)
  36. 36. BUILDING WITH ASCIIDOCTOR plugins { id 'org.asciidoctor.convert' version '1.5.2' }
  37. 37. BUILDING WITH ASCIIDOCTOR repositories { jcenter() } asciidoctor { sources { include 'example.adoc' } backends 'html5' }
  38. 38. PUBLISHING Built-in to Maven, Ivy Metadata publishing for native projects still lacking Various plugins for AWS and other cloud storage Plain old copies to FTP, SFTP etc.
  39. 39. MORE SUPPORT… Official buildsystem for Android Docker Hadoop
  40. 40. TOUR DE FORCE Build a distributable application packaged as as ZIP Runnable via shell script or batch file Contains classes written Java, Groovy & Kotlin source Test source code with Spock Framework
  41. 41. TOUR DE FORCE plugins { id 'java' id 'groovy' id 'com.zoltu.kotlin' version '1.0.1' id 'application' } repositories { jcenter() } dependencies { compile 'org.codehaus.groovy:groovy-all:2.4.3' compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.1-1' testCompile 'org.spockframework:spock-core:1.0-groovy-2.4' } version = '1.0' mainClassName = "gradle.workshop.HelloJava" compileGroovy.dependsOn compileKotlin
  42. 42. ENDGAME Gradle is breaking new ground Ever improving native support Continuous performance improvements Go find some more plugins at https://plugins.gradle.org
  43. 43. ABOUT THIS PRESENTATION Written in Asciidoctor Styled by asciidoctor-revealjs extension Built using: Gradle gradle-asciidoctor-plugin gradle-vfs-plugin Code snippets tested as part of build Source code: https://github.com/ysb33r/GradleLectures/tree/MkJugMar201
  44. 44. THANK YOU Email: Twitter / Ello : @ysb33r #idiomaticgradle ysb33r@gmail.com https://leanpub.com/idiomaticgradle
  45. 45. MIGRATIONS
  46. 46. ANT TO GRADLE Reflect Ant Build into Gradle ant.importBuild('build.xml')
  47. 47. MAVEN TO GRADLE Go to directory where pom.xml is and type gradle init --type pom
  48. 48. USEFUL STUFF
  49. 49. PUBLISHING VIA VFS plugins { id "org.ysb33r.vfs" version "1.0-beta3" } task publishToWebserver << { vfs { cp "${buildDir}/website", "ftp://${username}:${password}@int.someserver.com/var/www", recursive : true, overwrite : true } }

×