简体   繁体   中英

How to run a single task in in Eclipse with gradle buildship?

Currently I have in my gradle.build file the tasks:

task helloA {
    println 'hello A!'
}

task helloB {
     println 'hello B!'
     }

However executing task helloA via Gradle Tasks/other/helloA prints on the console:

hello A!
hello B!
:helloA UP-TO-DATE

BUILD SUCCESSFUL

However I would expect it to just print: 'hello A!' instead of

hello A!
hello B!

together.

How do I change that? I read through the gradle docs, but coudln't find something about that apart from some extensive workaround.

No task is executed at all in your buildfile, they are just configured.

Be aware that there are three phases in a Gradle run. Initialization, configuration and execution. In initialization phase, you define which projects are part of the build and where they are on disc (basically settings.gradle execution). In configuration phase all tasks are configured. In execution phase the tasks that need to be executed (explicitly called tasks or default tasks, depended upon directly or transitively by explicitly called or default tasks).

Try this and you will see:

task helloA {
    println 'configure A!'
    doLast {
        println 'execute A!'
    }
}

task helloB {
    println 'configure B!'
    doLast {
        println 'execute B!'
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM