zoukankan      html  css  js  c++  java
  • Groovy intro

    1. basic example

    println "hello, this line is outside of any task"
    
    task stringsAndTypes << {
        // TODO: Run `$ gradle sAT`
        println "Nice work abbreviating the task name"
    
        // TODO: Create a variable named foo and assign it the value 4.2
        def foo = 4.2
    
        // TODO: Print the value and class of foo
        println "foo is of type: ${foo.class} and has value: $foo"
    
        // TODO: Use string interpolation to print the square root of 127
        // HINT: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
        println "The square root of 127 is ${Math.sqrt(127)}"
    
        // TODO: Assign the current date to foo and print it, along with its type
        // HINT:
        // http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html
        foo = new java.util.Date()
        println "foo is now of type: ${foo.class} and has value: $foo"
    
    
        // TODO: Use the `substring` method to extract my name from this string
        def hello = "Hello, Jeremy."
        def name = hello.substring(7, 13)
    
        // TODO: Use `toUpperCase` to capitalize and print my name
        println name.toUpperCase()
    }
    
    
    task closures << {
        // TODO: Declare a closure that takes two arguments and adds them together
        // HINT: http://groovy.codehaus.org/Closures
        def addTwo = {x, y -> x + y}
    
        // TODO: Call your closure with arguments 17 and 25, and print the result
        // Beware that something like `println addTwo 17, 25` is ambiguous
        println addTwo(17,25)
    }
    
    task lists << {
        // TODO: Declare a list containing 5 of your favorite candies
        // HINT: Try searching for "groovy list literal"
        def candyList = ["Tomatoes","Carrots","Spinach","Radishes","Beef"]
    
        // TODO: Create a new list of your candies in all caps
        // HINT: http://groovy.codehaus.org/Tutorial+2+-+Code+as+data,+or+closures
        def capitalCandies = candyList.collect{it.toUpperCase()}
    
        // TODO: Print each capital candy
        capitalCandies.each{println it}
    }
    
    task foobar << {
        def foo = "bar"
        println "$foo + foo equals ${foo + 'foo'}"
    }

     2. dependency

    (1) dependsOn

    task putOnSocks {
        doLast {
            println "Putting on Socks."
        }
    }
    
    task putOnShoes {
        dependsOn "putOnSocks"
        doLast {
            println "Putting on Shoes."
        }
    }

    (2)finalizedBy

    task eatBreakfast {
        finalizedBy "brushYourTeeth"
        doLast{
            println "Om nom nom breakfast!"
        }
    }
    
    task brushYourTeeth {
        doLast {
            println "Brushie Brushie Brushie."
        }
    }
  • 相关阅读:
    android29
    android28
    android27
    android26
    Dynamics CRM2011 MspInstallAction failed when installing an Update Rollup
    Dynamics CRM Import Solution Attribute Display Name description is null or empty
    The service cannot be activated because it does not support ASP.NET compatibility
    IIS部署WCF报 无法读取配置节“protocolMapping”,因为它缺少节声明
    Unable to access the IIS metabase.You do not have sufficient privilege
    LM算法与非线性最小二乘问题
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/4555998.html
Copyright © 2011-2022 走看看