build.gradle - Controlling Gradle task execution -
in build.gradle script, have lot of tasks, each depending on 0 or more other tasks.
there 3 'main' tasks can called: moduleinstallation, backupfiles , restorefiles.
here's question: able tell gradle tasks execute , don't need execute. example, when calling moduleinstallation, want depending tasks execute (regardless of up-to-date flag), not restore tasks. i've tried altering phase in tasks executed (e.g. config phase, execution phase,...) , couple of other things, tasks keep getting executed.
a solution i've thought of stating in main tasks that, when main task called (f.e. moduleinstallation), set up-to-date flag of non-related tasks false, don't executed. possible?
edit: here's example:
when moduleinstallation called (which depends on backupfiles), restorefiles (which depends on restorefromdate) executed too.
first main action
task moduleinstallation << { println "hello moduleinstallation" } task backupfiles { dolast { println "hello backupfiles" } } second main action
task restorefiles { println "hello restorefiles" } task restorefromdate { println "hello restorefromdate" } dependencies:
moduleinstallation.dependson backupfiles restorefiles.dependson restorefromdate so when type gradle moduleinstallation in terminal, following output:
hello restorefromdate hello restorefiles hello backupfiles hello moduleinstallation
the second snippet has use dolast (or << shortcut) first snippet. otherwise, code configuration code , always evaluated, no matter tasks going executed. in other words, it's not restorefiles , restorefromdate tasks being executed here (as 1 can tell bits of command line output don't show), (only) configuration code.
to better understand what's going on here (which crucial understanding gradle), recommend study build lifecycle chapter in gradle user guide.
Comments
Post a Comment