2012年12月10日月曜日

GradleでTask Ruleを使ってタスクを定義する

GradleでTask Ruleを使ってタスクを定義する方法は、以下の通り。


 addRuleの第1引数に指定したdescriptionは、tasksタスク実行時にRulesのセクションに表示される。第2引数のクロージャでは、特定の条件にマッチするタスク名に対応するタスクを定義する。この例では、‘sample’で始まるタスク名をもつタスクを定義している。

tasksタスクを実行した結果は、以下の通り。
$ gradle tasks
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Help tasks
----------
dependencies - Displays all dependencies declared in root project 'aaa'.
dependencyInsight - Displays the insight into a specific dependency in root pr
ect 'aaa'.
help - Displays a help message
projects - Displays the sub-projects of root project 'aaa'.
properties - Displays the properties of root project 'aaa'.
tasks - Displays the tasks runnable from root project 'aaa' (some of the displ
ed tasks may belong to subprojects).

Rules
-----
Pattern: sample<ID>

To see all tasks and more detail, run with --all.

Task Ruleとして定義したタスクを実行した結果は、以下の通り。
$ gradle sample1 sample2
:sample1
1
:sample2
2

関連リンク

0 件のコメント:

コメントを投稿