Gradle

5,680 views

Published on

Quick Gradle tutorial

Published in: Technology

Gradle

  1. 1. www.adastra.czGradleModern Automation ToolVít Kotačka25. 4. 2013
  2. 2. Gradle? What is it?• Build automation tool– building, testing, deployment, reporting etc.• Domain Specific Language (DSL) based on Groovy• Combines the power and flexibility of Ant with thedependency management and conventions of Maven.• Features are added by plugins.• Out-of-the-box support: Java, Groovy, Scala, Web, OSGi• Free and Open Source (Apache Licence)www.adastra.cz 2
  3. 3. Is it really good?www.adastra.cz 3
  4. 4. Project & Task• Project represents a component which can be built.• Project defines a related set of tasks.ProjectDir/build.gradle• Task is an atomic unit of work which a build performs.task helloWorld << {println Hello, world!}www.adastra.cz 4
  5. 5. Java Projectapply plugin: java• Maven default layout– src/main/java– src/main/resource– src/test/java– src/test/resources• Additional tasks– clean– build– jar– test– javadocwww.adastra.cz 5
  6. 6. Unit Testsapply plugin: javarepositories {mavenCentral()}dependencies {testCompile junit:junit:4.11}• JUnit default• TestNG explicittest.useTestNG()JUnitwww.adastra.cz 6
  7. 7. Web Projectapply plugin: warwar {baseName = deepThought}dependencies {providedCompile javax.servlet:servlet-api:3.0}• Project layout– src/main/webapp• Additional task– warJUnitwww.adastra.cz 7
  8. 8. Jettyconfigurations {jetty8}dependencies {jetty8 org.mortbay.jetty:jetty-runner:8.1.10.v20130312}task runJetty8(type: JavaExec) {main = org.mortbay.jetty.runner.Runnerargs = [war.archivePath]classpath configurations.jetty8}• Plugin jettysupports Jetty 6only.JUnitwww.adastra.cz 8
  9. 9. Code Qualityapply {plugin checkstyleplugin pmdplugin findbugsplugin jdepend‚plugin sonar}www.adastra.cz 9
  10. 10. Multi Projectbuild.gradleallprojects {task work << {...}}subprojects { ... }project(:nonJava) { ... }settings.gradleinclude nonJava,java,webwww.adastra.cz 10
  11. 11. Antbuild.xml<project name="DeepThought"><property name="ultimateAnswer" value="12"/><target name="answer"><echo>${ultimateAnswer}</echo></target></project>build.gradleant.importBuild ant/build.xmlant.properties[ultimateAnswer] = 42www.adastra.cz 11
  12. 12. Gradle GUIgradle --guiwww.adastra.cz 12
  13. 13. IDE Supportwww.adastra.cz 13
  14. 14. About Mehttp://sw-samuraj.cz@sw_samurajhttp://linkedin.com/in/vitkotackawww.adastra.cz 14
  15. 15. www.adastra.cz 15

×