Uploaded on

by Maxim Stepanenko

by Maxim Stepanenko

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,604
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Gradle (http://www.gradle.org)Maxim Stepanenko, Architect www.ExigenServices.com
  • 2. Traditional build systems• Make, autotools• Ant (build, deploy), ant + ivy (dependency mgmt.)• Maven (dependency and lifecycle mgmt.)• Can be extended using pluginsPlug-in architectures severely limit the ability for build tools to grow gracefully as projectsbecome more complex. We have come to feel that plug-ins arethe wrong level of abstraction, and prefer language-based toolslike Gradle and Rake instead, because they offer finer-grainedabstractions and more flexibility long term.http://thoughtworks.fileburst.com/assets/technology-radar-october-2012.pdf2
  • 3. Alternative build systems• Gradle (DSL + groovy + Ivy)• Rake (DSL + ruby)• Apache Buildr (DSL + ruby)• Scons (DSL + python)• Simple Build Tool (Scala + DSL)• All this systems based on a true languages: ruby, python etc.3
  • 4. Brief Gradle benefits• You could script parts of the build that were too difficult to describe through "build by convention".• The general flexibility to define the build and directories the way that seemed to make sense.• The entire conceptualization of the build process is much cleaner. You not only have dependencies between modules but you can also define dependencies on tasks, modules, directories. It is already possible to say that one module depends on the compiled classes of another module as opposed to the output (jar) of the module.• Each project/module can have multiple "source sets". A "source set" defines a named group of source directories, output directories, resource directories.• "how am I going to solve this?" as opposed to "what are the viable options my build tool is going to leave me to achieve this?"• "incremental build“. It understands when things have changed and when they have not and when certain portions of the build are really needed.• Can publish artifacts to Maven repositories and generate accurate POM.• IDE project generation (Eclipse – spring tool suite + greclipse / IntelliJ).https://community.jboss.org/wiki/GradleWhy?_sscc=t4
  • 5. Gradle usage in real world• Hibernate• Grails• Groovy• SpringIntegration• SpringSecurity5
  • 6. Gradle build file 1apply plugin: javaapply plugin: eclipse‘sourceCompatibility = 1.7targetCompatibility = 1.7version = 1.0jar { manifest { attributes Implementation-Title: ‘Title’, Implementation-Version: version }}repositories { mavenCentral()}dependencies { compile group: org.slf4j, name: slf4j-log4j12, version: 1.7.2 testCompile group: junit, name: junit, version: 4.10}…} 6
  • 7. Gradle build file 2task simpleCalculation << { def x = 30 def y = 20 if( x > y) { print x > y: + x + " - " + y + " = " + (x - y) } else { print x < y: + y + " - " + x + " = " + (y - x) }}task simple (dependsOn: ‘simpleCalculation’, description: ‘Simple task’){ doFirst { print "doFirst: ${it.name}" + System.getProperty("line.separator") }} 7
  • 8. Build options• gradle jar• gradle --daemon jar• GRADLE_OPTS="-Dorg.gradle.daemon=true"• gradle --gui• gradle --profile• gradle --dry-run  run tasks without execution8
  • 9. Plugins• apply plugin: java• apply plugin: eclipse‘• apply plugin: scala‘• apply plugin: application• apply plugin: maven• apply plugin: signing9
  • 10. Source sets (SS)• Java plugin source sets (main, test)• Provided tasks: compile<SS>Java, process<SS>Resources, <SS>Classes• Add new source set10
  • 11. 1.api/javaapi/resources2.sourceSets { api main { compileClasspath = compileClasspath + files(api.output.classesDir) }}classes.dependsOn apiClasses3.gradle build 11
  • 12. Dependency management• Groovy use Ivy under the hood + some syntactic sugar• Support maven and Ivy repositories + custom repositories• Logical groups of dependencies (compile group, testCompile group)• Transitive version conflicts (different sl4j-api versions)configurations.all { resolutionStrategy { failOnVersionConflict() }}gradle dependencies12
  • 13. Testing• JUnit tests by defaul• TestNG as well, test.useTestNG()• Configurabletest { systemProperty sysProp, value jvmArgs -Xms256m, -Xmx512m debug = true ignoreFailures = true enableAssertions = true maxParallelForks = 4 forkEvery = 10 // create new thread after 10 tests}13
  • 14. Running, publishing• Run application (apply plugin: ‘application’ )• Startup scripts (for win and linux)• Zip archive (with lib folder)• Publish jar and zip files to repositories (gradle uploadArchives)• Publish to maven repository• Publish signed artifacts (PGP only)14
  • 15. Publish to local maven repositoryapply plugin: mavenarchivesBaseName = "algorithms"group = com.max.algorithmsversion = 1.0uploadArchives { repositories { mavenDeployer { repository(url: file:./maven) } }} 15
  • 16. Multi-project builds• DAG full dependency traversation• Hierarchical structure• Flat structure• Possible to have one build file per multi module project• Define dependencies between tasks in different projects• Compile/runtime dependencies between projects16
  • 17. Mixed languages projects• C++, scala, groovy• Cross compiled source bases• Fast scala compilation (similar to SBT) apply plugin: scala‘ ext.scala_version = 2.9.2 sourceSets.main.scala.srcDir "src/main/java" sourceSets.main.java.srcDirs = [] dependencies { scalaTools group: org.scala-lang, name: scala-compiler, version: scala_version scalaTools group: org.scala-lang, name: scala-library, version: scala_version compile group: org.scalatra, name: scalatra_2.9.1, version: 2.1.0.M1 runtime group: org.scalatra, name: scalatra_2.9.1, version: 2.1.0.M1 }17
  • 18. 18
  • 19. Code quality• gradle check• Checkstyle• PMD• FindBugs• JDepend• Sonar• CodeNarc (static analyzer for groovy code)19
  • 20. Checkstyle results20
  • 21. Findbugs21
  • 22. JDepend22
  • 23. PMD23
  • 24. Custom taskstask info(type: InfoTask)class InfoTask extends DefaultTask { @TaskAction def info(){ print “Current Gradle version: $project.gradle.gradleVersion” }}24
  • 25. Custom pluginapply plugin: InfoPluginclass InfoPlugin implements Plugin<Project> { void apply(Project project) { project.task(info) << { println "Running Gradle: $project.gradle.gradleVersion" } }} 25
  • 26. Continuous integration• Jenkins (gradle plugin)• JetBrains TeamCity• Atlassian Bamboo26