Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which gradle task is present by default in any gradle project?

Tags:

gradle

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.

like image 815
impks Avatar asked Oct 24 '25 19:10

impks


1 Answers

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.

like image 166
lance-java Avatar answered Oct 26 '25 13:10

lance-java



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!