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.

Why gradle

694 views

Published on

Gradle Makes Everything Great

Published in: Technology
  • Be the first to comment

Why gradle

  1. 1. Why Gradle? Gradle makes the impossible possible, the possible easy and the easy elegant
  2. 2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> </project> apply plugin: 'java' group = 'com.mycompany.app' archivesBaseName = 'my-app' version = '1.0-SNAPSHOT' repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.11' } Maven vs Gradle
  3. 3. Recognition by ThoughtWorks “Two things have caused fatigue with XML-based build tools like Ant and Maven: too many angry pointy braces and the coarseness of plug-in architectures. While syntax issues can be dealt with through generation, plug-in architectures severely limit the ability for build tools to grow gracefully as projects become more complex. We have come to feel that plug-ins are the wrong level of abstraction, and prefer language- based tools like Gradle and Rake instead, because they offer finer-grained abstrac- tions and more flexibility long term.”
  4. 4. Gradle’s Compelling Feature Set
  5. 5. Convention over Configuration - Build Cycle Ant was cool but it has maintainability issues, duplicated code. Maven picks up and idea of convention over configuration. Repeated steps are standardized. Maven’s core logic can be extended with plugins Maven has life cyclye; Compile, unit and integration tests, assembling the artifact, deploying the artifact to local repo, releasing the artifact to remote repo. Dependency Management over maven central
  6. 6. Shortcomings - Maven “My way or Highway” ● Maven proposes a default structre and lifecycle for a project that often is too restrictive ● Writing custom extensions for maven is hard. You must learn MOJO ● Plugin versions may be trouble for your environment.
  7. 7. Which one would you prefer? Flexibility and extensibility but get weak project standardization, tons of boilerplate code no support for dependency management by picking Ant; Or You go with maven, which offers a convention over configuration approach and a seamlessly integrated dependency manager, but an overly restrictive mindset and cumbersome plugin system. Or A build tool that offers you both like Gradle!
  8. 8. Here comes Gradle Groovy instead of XML is declerative, readable, and it clearly express the intention
  9. 9. What is possible with Gradle while it is impossible with others Directed Acyclic Graph: In maven goals must depend on each other even if they have no dependencies, in gradle must not Task Exclusion: In gradle you exclude any task from being run and all its dependend tasks Task Ordering: Gradle supports shouldRunAfter, mustRunAfter operations Task Dependency Inference: Gradle aware of what it produce. Any task that has java bin directory as input will automatically trigger compileJava. True Multi Task Execution: You can specify multiple tasks when executing the build and no task in the resulting DAG is executed twice Dry Run: Show tasks in which order without executing them Ex: gradle -m clean compile Build automatically when sources change, Declarative DSL
  10. 10. Integration With Other Build Tools Gradle builds are 100%compatible with Maven and Ivy Repos. You can retrieve and publish your own artifacts. Also Gradle provides converter for existing maven builds
  11. 11. Deployment Pipline ● Compile the code ● Runing unit and integration tests ● Performing static code analysis and generating test coverage ● Creating the distribution ● Provisioning the target environment ● Deploying the deliverable ● Performing smoke and automated functional tests
  12. 12. Let’s Get it Started task helloWorld{ doLast { println ‘Hello World’ } } task helloWorld<<{ println ‘Hello World’ } task helloWorld{ doFirst{ ‘Hello’ } doLast{ ‘World’ } } $ gradle -q helloWorld Hello World! def chant(){ ant.echo(message: ‘Hell Ant yeah!’) } 3.times { task “yayGradle$it” <<{ println ‘Gradle rocks’ } } yayGradle0.dependsOn startSession yayGradle2.dependsOn yayGradle1, yayGradle0 task groupTherapy(dependsOn: yayGradle2) $ #exclude task $ gradle groupTherapy -x yayGradle0 $ #show all tasks $ gradle -q tasks --all
  13. 13. Gradle Daemon When using gradle day to day basis, you’ll find yourself having to run your build repetitvely. Each time you initiate a build, the JVM has to be started, Gradle dependency’s has to be loaded into class loader, and the project model has to be constructed. This procedure usually takes 2 seconds. Gradle daemon to the rescue! $ ~/.gradle/gradle.properties org.gradle.daemon=true
  14. 14. Let’s do some examples!
  15. 15. Dependency Management Either one is available throu Gradle, Maven or Ivy Repositories apply plugin: ‘java’ repositories { mavenCentral() mavenLocal() maven { url “http://dev.foreks.com/nexus/content/repositories/release } ivy { url “http://repo.foreks.com/ivy/repo” url “../local-repo” } } dependencies{ compile ‘org.hibernate:hibernate-core:3.6.7.Final’ }
  16. 16. Dependency Configurations Default configurations are compile, runtime, testCompile, testRuntime configurations{ perfCompile } dependencies{ perfCompile(‘org.openjdk.jmh:jmh-core:1.11.2’, ‘org.openjdk.jmh:jmh-generator-bytecode:1.11.2’, project) compile ‘org.codehaus.groovy:groovy-all:2.4.4’ testCompile(‘junit:junit:4.+’, ‘org.spockframework:spock-core:1.0-groovy-2.4’) testRuntime(‘com.athaydes:spock-reports:1.2.7’) } apply plugin: ‘eclipse’ eclipse { classpath { plusConfigurations+=[configurations.testCompile, configurations. perfCompile] } }
  17. 17. Publishing artifacts apply plugin: ‘maven’ uploadArchives{ repositories{ mavenDeployer{ repository(url: ‘ http://dev.foreks.com/nexus/content/repositories/releases ’){ authentication(userName:nexusUsername, passowrd:nexusPassword) } snapshotRepository(url: ‘ http://dev.foreks.com/nexus/content/repositories/snapshots ’){ authentication(userName:nexusUsername, password:nexusPassword) } } } }
  18. 18. Thanks

×