SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
Gradle



         Tomek Kaczanowski
         http://kaczanowscy.pl/tomek




                              2010
IMPORTANT

 All code samples are
compatible with version
     0.9-preview-3

                          2010
There are
no simple builds


                   2010
2010
• Flexible build tool
• Based on convention over configuration idea
• Groovy (DSL)
• Open source
• Project Manager: Hans Docter
• GitHub
• First release: April 2008



                     making the impossible possible,
              the possible easy, and the easy elegant
                                 -- Moshé Feldenkrais

                                                        2010
Table of Contents
• Warm-up
   – Command line, GUI, tasks, DAG
• Competition
   – Ant, Maven & Co
• MyProject: Core, UI:Web, UI:Swing
   – CoC + customization
   – Compilation (Java, Groovy), JAR/WAR,
   – artifacts handling (repositories & dependencies),
   – custom logic (tasks)
   – Gradle & Ant
   – Multi-module builds
       • Layout
       • Partial builds
                                                         2010
Intro




        2010
Intro - DAG
• Read and manipulate graph of tasks, e.g.:
    task release(dependsOn: assemble) << {
           println 'We release now‘
    }

    gradle.taskGraph.whenReady {
        taskGraph ->
           if (taskGraph.hasTask (':release')) {
                  version = '1.0‘
           } else {
                  version = '1.0-SNAPSHOT‘
           }
    }


                                                   2010
Intro - DAG
• Read and manipulate graph of tasks, e.g.:
   gradle.taskGraph.beforeTask {
       Task task ->
           println "executing $task ..."
   }

   gradle.taskGraph.afterTask {
       Task task, TaskState state ->
          if (state.failure ) {
                 println "FAILED"
          }
          else {
                 println "done"
          }
   }
                                           2010
Intro - summary
• DSL
• Command line, GUI (+ IDE plugins)
  – Reports
  – Prunning of tasks tree (-x)
  – User friendly (camel case, dry run)
• Rich tasks layer
  – Tasks dependencies
  – DAG
  – Runtime manipulation
                                          2010
Frameworkitis is the disease that a framework
wants to do too much for you or it does it in a way that you
don't want but you can't change it. It's fun to get all this
functionality for free, but it hurts when the free
functionality gets in the way. […] To get the desired
behavior you start to fight against the framework. And at this
point you often start to lose, because it's difficult to bend the
framework in a direction it didn't anticipate.

[…] Frameworks try to be in control and tell you when to do
what. A toolkit gives you the building blocks but leaves it
up to you to be in control.

                             Erich Gamma, www.artima.com


                                                             2010
2010
2010
2010
MyProject
• Core
  – Classes used by UI subprojects
  – Java
• UI:Web
  – Web application
• UI:Swing
  – Desktop application
  – Groovy


                                     2010
.
|-- build.gradle
`-- src
    |-- main
    |   `-- java
    `-- test
        `-- java




   Convention
      over
  configuration
                   2010
.
|-- build.gradle
`-- src
    |-- main
    |   `-- java
    `-- test
        `-- java



apply plugin: 'java'




   Convention
      over
  configuration
                       2010
.
|-- build.gradle
`-- src
    |-- main
    |   `-- java
    `-- test
        `-- java



apply plugin: 'java'   apply plugin: 'java'

                       version="1.0-SNAPSHOT"

                       archivesBaseName = "whatever"

 Configuration         libsDirName="build/artifacts"

   is always
    possible
                                                   2010
.                      .
|-- build.gradle       |-- build.gradle
`-- src                |-- src
    |-- main           `-- test
    |   `-- java
    `-- test
        `-- java



apply plugin: 'java'




 Configuration
   is always
    possible
                                          2010
.                      .
|-- build.gradle       |-- build.gradle
`-- src                |-- src
    |-- main           `-- test
    |   `-- java
    `-- test
        `-- java
                       apply plugin: 'java'

                       sourceSets {
apply plugin: 'java'       main {
                               java {
                                    srcDir 'src'
                               }
                           }
                           test {
 Configuration                 java {
                                    srcDir 'test'
   is always                   }

    possible           }
                           }

                                              2010
.                  apply plugin: 'java'
|-- build.gradle
`-- src
    |-- main
    |   `-- java
    `-- test
        `-- java




  Convention
     over
 configuration
                                          2010
.                  apply plugin: 'java'
|-- build.gradle
`-- src            repositories {
    |-- main           mavenCentral()
    |   `-- java
                   }
    `-- test
        `-- java
                   dependencies {
                     compile
                       'org.hibernate:hibernate:3.1.3',
                       'commons-lang:commons-lang:2.5'
                     testCompile
                       'junit:junit:4.8.1'
                   }



  Convention
     over
 configuration
                                                    2010
apply plugin: 'java'

               repositories {
  Groups of        mavenCentral()

dependencies   }

               configurations {
                 pmd
               }

               dependencies {
                 compile
                    'org.hibernate:hibernate:3.1.3',
                    'commons-lang:commons-lang:2.5'
                 testCompile
                    'junit:junit:4.8.1'
                 pmd
                    'pmd:pmd:4.2.5'
               }


                                                 2010
apply plugin: 'java'                  <?xml version="1.0" encoding="UTF-8"?>                  <project name="simple" default="dist" basedir=".">
                                      <project xmlns="http://maven.apache.org/POM/4.0.0"      <property name="src" location="src/main/java" />
version = '1.0-SNAPSHOT'              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   <property name="srcTest" location="src/test/java" />
                                      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   <property name="build" location="build" />
repositories {                        http://maven.apache.org/maven-v4_0_0.xsd">              <property name="dist" location="${build}/lib" />
      mavenCentral()                   <modelVersion>4.0.0</modelVersion>
}                                      <groupId>pl.gradle</groupId>                           <path id="classpath.test">
                                       <artifactId>simple</artifactId>                        <pathelement location="libs/junit-4.8.1.jar" />
dependencies {                         <packaging>jar</packaging>                             <pathelement location="${srcTest}" />
    testCompile 'junit:junit:4.8.1'    <version>1.0-SNAPSHOT</version>                         <pathelement location="${build}/classes" />
}                                      <dependencies>                                          <pathelement location="${build}/test-classes" />
                                        <dependency>                                          </path>
                                         <groupId>junit</groupId>
                                         <artifactId>junit</artifactId>                       <target name="init">
                                         <version>4.8.1</version>                              <mkdir dir="${build}/classes" />
                                         <scope>test</scope>                                   <mkdir dir="${build}/test-classes" />
                                        </dependency>                                         </target>
                                       </dependencies>
                                       <build>                                                <target name="compile" depends="init">
                                        <plugins>                                              <javac srcdir="${src}" destdir="${build}/classes" />
                                         <plugin>                                             </target>
                                          <groupId>org.apache.maven.plugins</groupId>
                                           <artifactId>maven-compiler-plugin</artifactId>     <target name="testCompile" depends="init">
                                           <configuration>                                     <javac srcdir="${srcTest}" destdir="${build}/test-classes">
                                            <source>1.5</source>                                <classpath refid="classpath.test" />
                                            <target>1.5</target>                               </javac>
                                           </configuration>                                   </target>
                                         </plugin>                                            <target name="test" depends="testCompile">
                                        </plugins>                                             <junit fork="yes" haltonfailure="yes">
                                       </build>                                                             <batchtest fork="yes">
                                      </project>                                                              <fileset dir="${srcTest}">
                                                                                                                 <include name="**/*Test.java" />
                                                                                                                 <include name="**/Test*.java" />
                                                                                                               </fileset>



      Convention
                                                                                                             </batchtest>
                                                                                                <classpath refid="classpath.test" />
                                                                                                <formatter type="plain"/>
                                                                                               </junit>



         over
                                                                                              </target>
                                                                                              <target name="dist" depends="compile">
                                                                                               <mkdir dir="${dist}" />
                                                                                               <jar jarfile="${dist}/simple.jar" basedir="${build}/classes" />


     configuration
                                                                                              </target>
                                                                                              <target name="clean">
                                                                                               <delete dir="${build}" />
                                                                                              </target>
                                                                                              </project>
                                                                                                                                                        2010
repositories {
                   mavenCentral()
               }
  More on
repositories




                                    2010
repositories {
                   mavenCentral()
                   mavenRepo urls:
  More on      'http://download.java.net/maven2'
                   flatDir name: 'localRepository',
repositories                dirs: 'lib''
               }




                                                      2010
repositories {
                           mavenCentral()
                           mavenRepo urls:
   More on             'http://download.java.net/maven2'
                           flatDir name: 'localRepository',
 repositories                       dirs: 'lib''
                       }



// Maven2 layout
someroot/[organisation]/[module]/[revision]/[module]-[revision].[ext]

// Typical layout for an ivy repository
someroot/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]

//Simple layout (the organization is not used, no nested folders.)
someroot/[artifact]-[revision].[ext]




                                                                 2010
apply plugin: 'java'
                  apply plugin: 'maven'
Maven artifacts
                  configure(install.repositories.
upload – local    mavenInstaller) {
    repo              pom.project {
                          version '1.0-Maven'
                          groupId 'myGroup'
                          artifactId 'myArtifact'
                      }
                  }




                                                2010
apply plugin: 'java'
                       apply plugin: 'maven'
Maven artifacts
                       configure(install.repositories.
upload – local         mavenInstaller) {
    repo                   pom.project {
                               version '1.0-Maven'
                               groupId 'myGroup'
                               artifactId 'myArtifact'
                           }
                       }




 ~/.m2/repository/myGroup/myArtifact/
 |-- 1.0-Maven
 |   |-- myArtifact-1.0-Maven.jar
 |   `-- myArtifact-1.0-Maven.pom
 `-- maven-metadata-local.xml
                                                     2010
Maven artifacts upload – remote repo

configurations {
    deployerJars
}
dependencies {
    deployerJars
      "org.apache.maven.wagon:wagon-ssh:1.0-beta-2"
}
uploadArchives {
    repositories.mavenDeployer {
        configuration = configurations.deployerJars
        repository(url: "scp://myrepo.com/releases") {
            authentication(userName: "me", password: "pass")
        }
    }
}
                                                         2010
Core




       2010
Core - summary
• Very concise build.gradle file
  – DSL
  – Convention over configuration
     • Configuration is always possible
• Backward compatibility
  – Respects standards (layout a'la Maven)
  – Ivy & Maven dependencies and repositories



                                                2010
Gradle & Maven – dependencies
        and repositories
• Full backward compatibility
• Download from and upload to Maven
  repos
  – Including generation of pom files
• Gradle offers more than Maven
  – Uses Apache Ivy
  – Mercury (Maven 3) will be supported


                                          2010
Gradle – custom logic
• Directly within build script (build.gradle)
   – Any Groovy code
   – Can import 3rd party classes




                                                2010
Gradle – custom logic
• Directly within build script (build.gradle)
   – Any Groovy code
   – Can import 3rd party classes
• Custom tasks
   – build.gradle says ”what”
   – ”how” described in task class




                                                2010
Gradle – custom logic
• Directly within build script (build.gradle)
   – Any Groovy code
   – Can import 3rd party classes
• Custom tasks
   – build.gradle says ”what”
   – ”how” described in task class
• Custom plugins
   – More powerful than tasks, but still very easy to create
   – Some shipped with Gradle:
      • Java, Groovy, Scala, War, Jetty, Maven, Code Quality, OSGi,
        Eclipse, Project Report
                                                                 2010
Gradle – custom logic
• Directly within build script (build.gradle)
   – Any Groovy code
   – Can import 3rd party classes
• Custom tasks
   – build.gradle says ”what”
   – ”how” described in task class
• Custom plugins
   – More powerful than tasks, but still very easy to create
   – Some shipped with Gradle:
      • Java, Groovy, Scala, War, Jetty, Maven, Code Quality, OSGi,
        Eclipse, Project Report
                                                                 2010
Custom logic :
         ”how” described in task class

public class ReportTask extends DefaultTask {

    def FileCollection jars

    @TaskAction def createReport() {
      def text = new StringBuilder()
      text.append("gradle -v".execute().text)
      jars.each {
        text.append("t- $it.namen")
      }
      println "GENERATING REPORT"
      new File('build/report.txt') << text
    }
}
                                                2010
Custom logic :
      ”what” described in build.gradle
import org.gradle.sample.report.ReportTask
configurations {
  myDependencies
}
dependencies {
  ...
  myDependencies 'org.jmock:jmock:2.5.1'
}

task generateReport(type: ReportTask) {
  jars =
       configurations.runtime + configurations.myDependencies
}




                                                                2010
Gradle – custom logic




                        2010
Web UI
apply plugin: 'war'
repositories {
    ...
}
dependencies {
  ...
}

|-- build.gradle
`-- src                      Convention
    `-- main
          |-- java
                                over
          |-- resources     configuration
          `-- webapp
                                            2010
Web UI
apply plugin: 'war'    :war - Generates a war archive
                       with all the compiled classes,
repositories {
                       the web-app content and the
    ...                libraries.
}
dependencies {
  ...
}



                           Convention
                              over
                          configuration
                                                        2010
Web UI
apply plugin: 'war'      :war - Generates a war archive
apply plugin: 'jetty'    with all the compiled classes,
                         the web-app content and the
repositories {           libraries.
    ...
}                        :jettyRun - Uses your files as
dependencies {           and where they are and deploys
  ...                    them to Jetty.
}
                         :jettyRunWar - Assembles the
                         webapp into a war and deploys
                         it to Jetty.




                                                          2010
Web UI




         2010
Gradle & Ant – import of build.xml
   <project>
           <target name="hello">
                   <echo>Hello, from Ant</echo>
           </target>
   </project>




                                                  2010
Gradle & Ant – import of build.xml
   <project>
           <target name="hello">
                   <echo>Hello, from Ant</echo>
           </target>
   </project>


      ant.importBuild "build.xml"
      task myTask(dependsOn: hello) << {
        println "depends on hello ant task"
      }




                                                  2010
Gradle & Ant – import of build.xml
   <project>
           <target name="hello">
                   <echo>Hello, from Ant</echo>
           </target>
   </project>


      ant.importBuild "build.xml"
      task myTask(dependsOn: hello) << {
        println "depends on hello ant task"
      }


            >gradle myTask
            :hello
            [ant:echo] Hello, from Ant
            :myTask
            depends on hello ant task

                                                  2010
Gradle & Ant – use of Ant tasks
    task zip << {
        ant.zip(destfile: 'archive.zip')   {
            fileset(dir: 'src') {
            include(name: '**.xml')
            exclude(name: '**.java')
        }
    }




                                               2010
Gradle & Ant – use of Ant tasks
    task zip << {
        ant.zip(destfile: 'archive.zip')      {
            fileset(dir: 'src') {
            include(name: '**.xml')
            exclude(name: '**.java')
        }
    }

            task dist(type: Zip) {
                from 'src/dist‘
                from configurations.runtime
                into('libs‘)
            }



                                                  2010
Gradle & Ant - summary
• Ant targets = Gradle tasks
• Import of build.xml
• Use of Ant
  – ant object available in every build.gradle
     • AntBuilder used beneath
  – some Ant tasks rewritten
     • for optimization purposes and to be consistent
       with other concepts of Gradle
• Gradle = Ant with a boost
                                                        2010
Desktop UI - Groovy
apply plugin: 'groovy'
repositories {
  mavenCentral()
}
dependencies {
  groovy "org.codehaus.groovy:groovy-all:1.7.3"
}




                                                  2010
Desktop UI - Groovy
apply plugin: 'groovy'
repositories {
  mavenCentral()
}
dependencies {
  groovy "org.codehaus.groovy:groovy-all:1.7.3"
}
task run (dependsOn: build) << {
  ant.java(classname:
        'org.gradle.sample.ui.swing.SwingApp',
      fork: true,
      classpath:
        "${sourceSets.main.runtimeClasspath.asPath}")
}

                                                        2010
Desktop UI




             2010
Web & Desktop UI - summary
• Convention over configuration makes
  things easy
• Jetty plugin available out-of-the-box
• Many JVM languages supported
  – Java, Groovy, Scala




                                          2010
Multi-module build
multi
|-- build.gradle
|-- settings.gradle
|-- core
|   `-- ...
`-- ui
    |-- swing
    |   `-- ...
    `-- web
        `-- ...




                                2010
Multi-module build
multi
|-- build.gradle
|-- settings.gradle
|-- core
|   `-- ...
|-- frontend
|   |-- swing
|   |   `-- ...
|   |-- android
|   |   `-- ...
|   `-- web
|       `-- ...
`-- backend
    `-- swing
        `-- ...
                                2010
Multi-module build
multi
|-- build.gradle
|-- settings.gradle
|-- core
|   `-- ...
`-- ui
    |-- swing
    |    `-- ...
    `-- web
         `-- ...

include "core", "ui:swing", "ui:web"




                                       2010
Multi-module build




                     2010
Multi-module build – how many
        build.gradle files?
multi                 multi
|-- build.gradle      |-- build.gradle
|-- settings.gradle   |-- settings.gradle
|-- core              |-- core
|   `-- ...           |   |-- build.gradle
`-- ui                |   `-- ...
    |-- swing         `-- ui
    |    `-- ...          |-- swing
    `-- web               |    |-- build.gradle
         `-- ...          |    `-- ...
                          `-- web
configure(:core) {        |    |-- build.gradle
  ...                          `-- ...
}

...                                         2010
Multi-module build - summary
•   Layout – its up to you
•   Number of build.gradle files – you decide
•   Smart (partial) builds
•   Project treated as tasks
    – You can depend on them




                                                2010
2010
2010
2010
2010
2010
2010
2010
Use
    Gradle
for your next project


                        2010
Links
• http://gradle.org
• http://gradle.biz
• http://docs.codehaus.org/display/GRADLE/
  Cookbook
• http://docs.codehaus.org/display/GRADLE/
  Releases



                                        2010
Thank you



     Tomek Kaczanowski
http://kaczanowscy.pl/tomek
Would be great if you could provide some feedback at
             tkaczano@poczta.onet.pl

                                                       2010

Weitere ähnliche Inhalte

Was ist angesagt?

Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
Igor Khotin
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
Evgeny Goldin
 

Was ist angesagt? (20)

The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developers
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
Js tacktalk team dev js testing performance
Js tacktalk team dev js testing performanceJs tacktalk team dev js testing performance
Js tacktalk team dev js testing performance
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
Continous delivery with sbt
Continous delivery with sbtContinous delivery with sbt
Continous delivery with sbt
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合
 
Custom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerCustom deployments with sbt-native-packager
Custom deployments with sbt-native-packager
 
Simple Build Tool
Simple Build ToolSimple Build Tool
Simple Build Tool
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writing
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 

Andere mochten auch

Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIII
Takuma Watabiki
 
function list
function listfunction list
function list
kyon mm
 
Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化
Kenichi Kambara
 
レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場
Hiroyuki Ohnaka
 
Jenkinsプラグインの作り方
Jenkinsプラグインの作り方Jenkinsプラグインの作り方
Jenkinsプラグインの作り方
Kiyotaka Oku
 

Andere mochten auch (20)

Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Spockを使おう!
Spockを使おう!Spockを使おう!
Spockを使おう!
 
The outlineoftestprocess
The outlineoftestprocessThe outlineoftestprocess
The outlineoftestprocess
 
Groovy Testing Aug2009
Groovy Testing Aug2009Groovy Testing Aug2009
Groovy Testing Aug2009
 
Spock Framework 2
Spock Framework 2Spock Framework 2
Spock Framework 2
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
G*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIIIG*におけるソフトウェアテスト・シーズンIII
G*におけるソフトウェアテスト・シーズンIII
 
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
 
Groovier testing with Spock
Groovier testing with SpockGroovier testing with Spock
Groovier testing with Spock
 
function list
function listfunction list
function list
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化
 
GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築
 
Gradle a new Generation Build Tool
Gradle a new Generation Build ToolGradle a new Generation Build Tool
Gradle a new Generation Build Tool
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場
 
Jenkinsプラグインの作り方
Jenkinsプラグインの作り方Jenkinsプラグインの作り方
Jenkinsプラグインの作り方
 

Ähnlich wie Gradle talk, Javarsovia 2010

Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 

Ähnlich wie Gradle talk, Javarsovia 2010 (20)

Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Gradle
GradleGradle
Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Why gradle
Why gradle Why gradle
Why gradle
 
Apache Maven basics
Apache Maven basicsApache Maven basics
Apache Maven basics
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
GradleFX
GradleFXGradleFX
GradleFX
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 

Mehr von Tomek Kaczanowski

33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 

Mehr von Tomek Kaczanowski (11)

2015 ACE! Conference slides
2015 ACE! Conference slides2015 ACE! Conference slides
2015 ACE! Conference slides
 
Grupowe podejmowanie decyzji
Grupowe podejmowanie decyzjiGrupowe podejmowanie decyzji
Grupowe podejmowanie decyzji
 
2013 DevFest Vienna - Bad Tests, Good Tests
2013 DevFest Vienna - Bad Tests, Good Tests2013 DevFest Vienna - Bad Tests, Good Tests
2013 DevFest Vienna - Bad Tests, Good Tests
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Sample Chapter of Practical Unit Testing with TestNG and Mockito
Sample Chapter of Practical Unit Testing with TestNG and MockitoSample Chapter of Practical Unit Testing with TestNG and Mockito
Sample Chapter of Practical Unit Testing with TestNG and Mockito
 
Practical Unit Testing with TestNG and Mockito
Practical Unit Testing with TestNG and MockitoPractical Unit Testing with TestNG and Mockito
Practical Unit Testing with TestNG and Mockito
 
GeeCON 2011 Who Watches The Watchmen? - On Quality Of Tests
GeeCON 2011 Who Watches The Watchmen? - On Quality Of TestsGeeCON 2011 Who Watches The Watchmen? - On Quality Of Tests
GeeCON 2011 Who Watches The Watchmen? - On Quality Of Tests
 
Convention Over Configuration - Maven 3, Polyglot Maven, Gradle and Ant
Convention Over Configuration - Maven 3, Polyglot Maven, Gradle and AntConvention Over Configuration - Maven 3, Polyglot Maven, Gradle and Ant
Convention Over Configuration - Maven 3, Polyglot Maven, Gradle and Ant
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Gradle talk, Javarsovia 2010

  • 1. Gradle Tomek Kaczanowski http://kaczanowscy.pl/tomek 2010
  • 2. IMPORTANT All code samples are compatible with version 0.9-preview-3 2010
  • 3. There are no simple builds 2010
  • 5. • Flexible build tool • Based on convention over configuration idea • Groovy (DSL) • Open source • Project Manager: Hans Docter • GitHub • First release: April 2008 making the impossible possible, the possible easy, and the easy elegant -- Moshé Feldenkrais 2010
  • 6. Table of Contents • Warm-up – Command line, GUI, tasks, DAG • Competition – Ant, Maven & Co • MyProject: Core, UI:Web, UI:Swing – CoC + customization – Compilation (Java, Groovy), JAR/WAR, – artifacts handling (repositories & dependencies), – custom logic (tasks) – Gradle & Ant – Multi-module builds • Layout • Partial builds 2010
  • 7. Intro 2010
  • 8. Intro - DAG • Read and manipulate graph of tasks, e.g.: task release(dependsOn: assemble) << { println 'We release now‘ } gradle.taskGraph.whenReady { taskGraph -> if (taskGraph.hasTask (':release')) { version = '1.0‘ } else { version = '1.0-SNAPSHOT‘ } } 2010
  • 9. Intro - DAG • Read and manipulate graph of tasks, e.g.: gradle.taskGraph.beforeTask { Task task -> println "executing $task ..." } gradle.taskGraph.afterTask { Task task, TaskState state -> if (state.failure ) { println "FAILED" } else { println "done" } } 2010
  • 10. Intro - summary • DSL • Command line, GUI (+ IDE plugins) – Reports – Prunning of tasks tree (-x) – User friendly (camel case, dry run) • Rich tasks layer – Tasks dependencies – DAG – Runtime manipulation 2010
  • 11. Frameworkitis is the disease that a framework wants to do too much for you or it does it in a way that you don't want but you can't change it. It's fun to get all this functionality for free, but it hurts when the free functionality gets in the way. […] To get the desired behavior you start to fight against the framework. And at this point you often start to lose, because it's difficult to bend the framework in a direction it didn't anticipate. […] Frameworks try to be in control and tell you when to do what. A toolkit gives you the building blocks but leaves it up to you to be in control. Erich Gamma, www.artima.com 2010
  • 12. 2010
  • 13. 2010
  • 14. 2010
  • 15. MyProject • Core – Classes used by UI subprojects – Java • UI:Web – Web application • UI:Swing – Desktop application – Groovy 2010
  • 16. . |-- build.gradle `-- src |-- main | `-- java `-- test `-- java Convention over configuration 2010
  • 17. . |-- build.gradle `-- src |-- main | `-- java `-- test `-- java apply plugin: 'java' Convention over configuration 2010
  • 18. . |-- build.gradle `-- src |-- main | `-- java `-- test `-- java apply plugin: 'java' apply plugin: 'java' version="1.0-SNAPSHOT" archivesBaseName = "whatever" Configuration libsDirName="build/artifacts" is always possible 2010
  • 19. . . |-- build.gradle |-- build.gradle `-- src |-- src |-- main `-- test | `-- java `-- test `-- java apply plugin: 'java' Configuration is always possible 2010
  • 20. . . |-- build.gradle |-- build.gradle `-- src |-- src |-- main `-- test | `-- java `-- test `-- java apply plugin: 'java' sourceSets { apply plugin: 'java' main { java { srcDir 'src' } } test { Configuration java { srcDir 'test' is always } possible } } 2010
  • 21. . apply plugin: 'java' |-- build.gradle `-- src |-- main | `-- java `-- test `-- java Convention over configuration 2010
  • 22. . apply plugin: 'java' |-- build.gradle `-- src repositories { |-- main mavenCentral() | `-- java } `-- test `-- java dependencies { compile 'org.hibernate:hibernate:3.1.3', 'commons-lang:commons-lang:2.5' testCompile 'junit:junit:4.8.1' } Convention over configuration 2010
  • 23. apply plugin: 'java' repositories { Groups of mavenCentral() dependencies } configurations { pmd } dependencies { compile 'org.hibernate:hibernate:3.1.3', 'commons-lang:commons-lang:2.5' testCompile 'junit:junit:4.8.1' pmd 'pmd:pmd:4.2.5' } 2010
  • 24. apply plugin: 'java' <?xml version="1.0" encoding="UTF-8"?> <project name="simple" default="dist" basedir="."> <project xmlns="http://maven.apache.org/POM/4.0.0" <property name="src" location="src/main/java" /> version = '1.0-SNAPSHOT' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <property name="srcTest" location="src/test/java" /> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 <property name="build" location="build" /> repositories { http://maven.apache.org/maven-v4_0_0.xsd"> <property name="dist" location="${build}/lib" /> mavenCentral() <modelVersion>4.0.0</modelVersion> } <groupId>pl.gradle</groupId> <path id="classpath.test"> <artifactId>simple</artifactId> <pathelement location="libs/junit-4.8.1.jar" /> dependencies { <packaging>jar</packaging> <pathelement location="${srcTest}" /> testCompile 'junit:junit:4.8.1' <version>1.0-SNAPSHOT</version> <pathelement location="${build}/classes" /> } <dependencies> <pathelement location="${build}/test-classes" /> <dependency> </path> <groupId>junit</groupId> <artifactId>junit</artifactId> <target name="init"> <version>4.8.1</version> <mkdir dir="${build}/classes" /> <scope>test</scope> <mkdir dir="${build}/test-classes" /> </dependency> </target> </dependencies> <build> <target name="compile" depends="init"> <plugins> <javac srcdir="${src}" destdir="${build}/classes" /> <plugin> </target> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <target name="testCompile" depends="init"> <configuration> <javac srcdir="${srcTest}" destdir="${build}/test-classes"> <source>1.5</source> <classpath refid="classpath.test" /> <target>1.5</target> </javac> </configuration> </target> </plugin> <target name="test" depends="testCompile"> </plugins> <junit fork="yes" haltonfailure="yes"> </build> <batchtest fork="yes"> </project> <fileset dir="${srcTest}"> <include name="**/*Test.java" /> <include name="**/Test*.java" /> </fileset> Convention </batchtest> <classpath refid="classpath.test" /> <formatter type="plain"/> </junit> over </target> <target name="dist" depends="compile"> <mkdir dir="${dist}" /> <jar jarfile="${dist}/simple.jar" basedir="${build}/classes" /> configuration </target> <target name="clean"> <delete dir="${build}" /> </target> </project> 2010
  • 25. repositories { mavenCentral() } More on repositories 2010
  • 26. repositories { mavenCentral() mavenRepo urls: More on 'http://download.java.net/maven2' flatDir name: 'localRepository', repositories dirs: 'lib'' } 2010
  • 27. repositories { mavenCentral() mavenRepo urls: More on 'http://download.java.net/maven2' flatDir name: 'localRepository', repositories dirs: 'lib'' } // Maven2 layout someroot/[organisation]/[module]/[revision]/[module]-[revision].[ext] // Typical layout for an ivy repository someroot/[organisation]/[module]/[revision]/[type]s/[artifact].[ext] //Simple layout (the organization is not used, no nested folders.) someroot/[artifact]-[revision].[ext] 2010
  • 28. apply plugin: 'java' apply plugin: 'maven' Maven artifacts configure(install.repositories. upload – local mavenInstaller) { repo pom.project { version '1.0-Maven' groupId 'myGroup' artifactId 'myArtifact' } } 2010
  • 29. apply plugin: 'java' apply plugin: 'maven' Maven artifacts configure(install.repositories. upload – local mavenInstaller) { repo pom.project { version '1.0-Maven' groupId 'myGroup' artifactId 'myArtifact' } } ~/.m2/repository/myGroup/myArtifact/ |-- 1.0-Maven | |-- myArtifact-1.0-Maven.jar | `-- myArtifact-1.0-Maven.pom `-- maven-metadata-local.xml 2010
  • 30. Maven artifacts upload – remote repo configurations { deployerJars } dependencies { deployerJars "org.apache.maven.wagon:wagon-ssh:1.0-beta-2" } uploadArchives { repositories.mavenDeployer { configuration = configurations.deployerJars repository(url: "scp://myrepo.com/releases") { authentication(userName: "me", password: "pass") } } } 2010
  • 31. Core 2010
  • 32. Core - summary • Very concise build.gradle file – DSL – Convention over configuration • Configuration is always possible • Backward compatibility – Respects standards (layout a'la Maven) – Ivy & Maven dependencies and repositories 2010
  • 33. Gradle & Maven – dependencies and repositories • Full backward compatibility • Download from and upload to Maven repos – Including generation of pom files • Gradle offers more than Maven – Uses Apache Ivy – Mercury (Maven 3) will be supported 2010
  • 34. Gradle – custom logic • Directly within build script (build.gradle) – Any Groovy code – Can import 3rd party classes 2010
  • 35. Gradle – custom logic • Directly within build script (build.gradle) – Any Groovy code – Can import 3rd party classes • Custom tasks – build.gradle says ”what” – ”how” described in task class 2010
  • 36. Gradle – custom logic • Directly within build script (build.gradle) – Any Groovy code – Can import 3rd party classes • Custom tasks – build.gradle says ”what” – ”how” described in task class • Custom plugins – More powerful than tasks, but still very easy to create – Some shipped with Gradle: • Java, Groovy, Scala, War, Jetty, Maven, Code Quality, OSGi, Eclipse, Project Report 2010
  • 37. Gradle – custom logic • Directly within build script (build.gradle) – Any Groovy code – Can import 3rd party classes • Custom tasks – build.gradle says ”what” – ”how” described in task class • Custom plugins – More powerful than tasks, but still very easy to create – Some shipped with Gradle: • Java, Groovy, Scala, War, Jetty, Maven, Code Quality, OSGi, Eclipse, Project Report 2010
  • 38. Custom logic : ”how” described in task class public class ReportTask extends DefaultTask { def FileCollection jars @TaskAction def createReport() { def text = new StringBuilder() text.append("gradle -v".execute().text) jars.each { text.append("t- $it.namen") } println "GENERATING REPORT" new File('build/report.txt') << text } } 2010
  • 39. Custom logic : ”what” described in build.gradle import org.gradle.sample.report.ReportTask configurations { myDependencies } dependencies { ... myDependencies 'org.jmock:jmock:2.5.1' } task generateReport(type: ReportTask) { jars = configurations.runtime + configurations.myDependencies } 2010
  • 40. Gradle – custom logic 2010
  • 41. Web UI apply plugin: 'war' repositories { ... } dependencies { ... } |-- build.gradle `-- src Convention `-- main |-- java over |-- resources configuration `-- webapp 2010
  • 42. Web UI apply plugin: 'war' :war - Generates a war archive with all the compiled classes, repositories { the web-app content and the ... libraries. } dependencies { ... } Convention over configuration 2010
  • 43. Web UI apply plugin: 'war' :war - Generates a war archive apply plugin: 'jetty' with all the compiled classes, the web-app content and the repositories { libraries. ... } :jettyRun - Uses your files as dependencies { and where they are and deploys ... them to Jetty. } :jettyRunWar - Assembles the webapp into a war and deploys it to Jetty. 2010
  • 44. Web UI 2010
  • 45. Gradle & Ant – import of build.xml <project> <target name="hello"> <echo>Hello, from Ant</echo> </target> </project> 2010
  • 46. Gradle & Ant – import of build.xml <project> <target name="hello"> <echo>Hello, from Ant</echo> </target> </project> ant.importBuild "build.xml" task myTask(dependsOn: hello) << { println "depends on hello ant task" } 2010
  • 47. Gradle & Ant – import of build.xml <project> <target name="hello"> <echo>Hello, from Ant</echo> </target> </project> ant.importBuild "build.xml" task myTask(dependsOn: hello) << { println "depends on hello ant task" } >gradle myTask :hello [ant:echo] Hello, from Ant :myTask depends on hello ant task 2010
  • 48. Gradle & Ant – use of Ant tasks task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java') } } 2010
  • 49. Gradle & Ant – use of Ant tasks task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java') } } task dist(type: Zip) { from 'src/dist‘ from configurations.runtime into('libs‘) } 2010
  • 50. Gradle & Ant - summary • Ant targets = Gradle tasks • Import of build.xml • Use of Ant – ant object available in every build.gradle • AntBuilder used beneath – some Ant tasks rewritten • for optimization purposes and to be consistent with other concepts of Gradle • Gradle = Ant with a boost 2010
  • 51. Desktop UI - Groovy apply plugin: 'groovy' repositories { mavenCentral() } dependencies { groovy "org.codehaus.groovy:groovy-all:1.7.3" } 2010
  • 52. Desktop UI - Groovy apply plugin: 'groovy' repositories { mavenCentral() } dependencies { groovy "org.codehaus.groovy:groovy-all:1.7.3" } task run (dependsOn: build) << { ant.java(classname: 'org.gradle.sample.ui.swing.SwingApp', fork: true, classpath: "${sourceSets.main.runtimeClasspath.asPath}") } 2010
  • 53. Desktop UI 2010
  • 54. Web & Desktop UI - summary • Convention over configuration makes things easy • Jetty plugin available out-of-the-box • Many JVM languages supported – Java, Groovy, Scala 2010
  • 55. Multi-module build multi |-- build.gradle |-- settings.gradle |-- core | `-- ... `-- ui |-- swing | `-- ... `-- web `-- ... 2010
  • 56. Multi-module build multi |-- build.gradle |-- settings.gradle |-- core | `-- ... |-- frontend | |-- swing | | `-- ... | |-- android | | `-- ... | `-- web | `-- ... `-- backend `-- swing `-- ... 2010
  • 57. Multi-module build multi |-- build.gradle |-- settings.gradle |-- core | `-- ... `-- ui |-- swing | `-- ... `-- web `-- ... include "core", "ui:swing", "ui:web" 2010
  • 59. Multi-module build – how many build.gradle files? multi multi |-- build.gradle |-- build.gradle |-- settings.gradle |-- settings.gradle |-- core |-- core | `-- ... | |-- build.gradle `-- ui | `-- ... |-- swing `-- ui | `-- ... |-- swing `-- web | |-- build.gradle `-- ... | `-- ... `-- web configure(:core) { | |-- build.gradle ... `-- ... } ... 2010
  • 60. Multi-module build - summary • Layout – its up to you • Number of build.gradle files – you decide • Smart (partial) builds • Project treated as tasks – You can depend on them 2010
  • 61. 2010
  • 62. 2010
  • 63. 2010
  • 64. 2010
  • 65. 2010
  • 66. 2010
  • 67. 2010
  • 68. Use Gradle for your next project 2010
  • 69. Links • http://gradle.org • http://gradle.biz • http://docs.codehaus.org/display/GRADLE/ Cookbook • http://docs.codehaus.org/display/GRADLE/ Releases 2010
  • 70. Thank you Tomek Kaczanowski http://kaczanowscy.pl/tomek Would be great if you could provide some feedback at tkaczano@poczta.onet.pl 2010