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."
        }
    }
  • 相关阅读:
    Opencv中cvCopy()和cvCloneImage()的区别(转)
    什么是DC?
    UpdateDate()函数的作用
    宏定义函数指针类型【转】
    将openCV中的IplImage格式的图片显示到Picture控件上
    C程序调用shell脚本共有三种方法
    memset ,memcpy ,memmove,strcpy 的根本区别 与实现
    sizeof strlen length()
    itoa 实现
    string 与 char * 转换
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/4555998.html
Copyright © 2011-2022 走看看