In my project I have several tasks in my build.gradle. I want those tasks to be independent while running. ie I need to run a single task from command line. But the command "gradle taskA" will run both taskA and taskB which I do not want. How to prevent a task being running?.
Here's a sample of what I am doing.
task runsSQL{ description 'run sql queries' apply plugin: 'java' apply plugin: 'groovy' print 'Run SQL' } task runSchema{ apply plugin: 'java' apply plugin: 'groovy' print 'Run Schema' }
Here's the output I'm getting.
single system property can be used to specify a single test. You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.
To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … e.g. gradlew clean allTests.
I guess the point that you missed is that you dont define tasks here but you configured tasks. Have a look at the gradle documentation: http://www.gradle.org/docs/current/userguide/more_about_tasks.html.
What you wanted is something like this:
task runsSQL (dependsOn: 'runSchema'){ description 'run sql queries' println 'Configuring SQL-Task' doLast() { println "Executing SQL" } } task runSchema << { println 'Creating schema' }
Please mind the shortcut '<<' for 'doLast'. The doLast step is only executed when a task is executed while the configuration of a task will be executed when the gradle file is parsed.
When you call
gradle runSchema
You'll see the 'Configuring SQL-Task' and afterwards the 'Creating schema' output. That means the runSQLTask will be configured but not executed.
If you call
gradle runSQL
Than you you'll see:
Configuring SQL-Task :runSchema Creating schema :runsSQL Executing SQL
runSchema is executed because runSQL depends on it.
You can use -x
option or --exclude-task
switch to exclude task from task graph. But it's good idea to provide runnable example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With