3

Which gradle task is present by default in any gradle project? I need to execute a custom task with every gradle build so I want to put dependsOn on that default task.

impks
  • 131
  • 4
  • What do you try to achieve? A task that is present is not necessarily executed. – Henry Jan 08 '19 at 06:52
  • this question/answer should help you : https://stackoverflow.com/questions/45183642/creating-a-task-that-runs-before-all-other-tasks-in-gradle . you cannot really use concept of "default task" in your case: default task will be executed only when you don't provide any task in the command line, this is not what you want I guess – M.Ricciuti Jan 08 '19 at 08:12

1 Answers1

5

You can answer this question yourself by creating an empty build.gradle and running

gradle tasks 

You won't find any tasks that actually do much, you'll see "setup" tasks (init & wrapper) and "help" tasks like model, help, dependencies, tasks etc but you won't find any "lifecycle tasks" such as build, check, assemble etc.

I'm guessing your actual question is "where do the lifecycle tasks such as build, check, assemble etc come from?" These lifecycle tasks are added by the Base plugin. The base plugin is applied by the java plugin and many others. If you want these lifecycle tasks in your custom build scripts and plugins you can

apply plugin: 'base' 
task foo {
    doLast { println 'foo' } 
} 
build.dependsOn foo

Note: Gradle is smart enough to apply any plugin only once. So many plugins in a single project can apply the base plugin.

lance-java
  • 25,497
  • 4
  • 59
  • 101