gradle01_helloworld

win7  64

gradle 2.1

build.gradle

task hello {
    doLast {
        println 'Hello world!'
    }
}

In a command-line shell, move to the containing directory and execute the build script with gradle
-q hello   
:

E:\download\developer\gradle\project_test\hello_world>gradle -q hello:

FAILURE: Build failed with an exception.

* What went wrong:
Project 'hello' not found in root project 'hello_world'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info o
r --debug option to get more log output.

E:\download\developer\gradle\project_test\hello_world>gradle -q --info
 hello
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'E:\download\developer\
gradle\project_test\hello_world\build.gradle'.
Included projects: [root project 'hello_world']
Evaluating root project 'hello_world' using build file 'E:\download\de
veloper\gradle\project_test\hello_world\build.gradle'.
All projects evaluated.
Selected primary task 'hello' from project :
Tasks to be executed: [task ':hello']
:hello (Thread[main,5,main]) started.
:hello
Executing task ':hello' (up-to-date check took 0.002 secs) due to:
  Task has not declared any outputs.
Hello world!
:hello (Thread[main,5,main]) completed. Took 0.145 secs.

BUILD SUCCESSFUL

Total time: 3.745 secs
E:\download\developer\gradle\project_test\hello_world>

There is a shorthand way to define a task like our hello task
above, which is more concise.

Example 6.3. A task definition shortcut

build.gradle

task hello << {
    println 'Hello world!'
}
时间: 2024-08-03 20:03:05

gradle01_helloworld的相关文章