與version 4.0開始,你必須運行gradle build --console=plain
看到任務相關的完整列表。
如果使用java-base
插件則依賴關係是:
$ gradle build --console=plain
:assemble
:check
:build
如果使用java
(其中automatically appliesjava-base
),則依賴關係是:
$ gradle build --console=plain
:compileJava
:processResources
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build
爲了看到上面圖片中顯示的確切的依賴關係鏈,我使用了一個可以在Gradle項目中運行的小Perl幫助程序。它產生一個dot串描述依賴圖:
#/bin/perl
use strict;
my @deps;
my %tasks;
getDeps($ARGV[0]);
printDot();
sub getDeps {
my $task = shift;
$tasks{$task} = "";
chomp(my @subtasks = `gradle $task`);
@subtasks = grep { $_ =~ "^:" } @subtasks;
pop @subtasks;
foreach(@subtasks) {
my ($s) = $_ =~ "^:(.*) ";
push @deps, "$task -> $s;";
if(!defined $tasks{$s}) {getDeps($s)}
}
}
sub printDot {
my $dot = "digraph main {\n";
if(@deps>1) {
foreach(@deps) {$dot .= "$_\n"}
} else {
$dot .= "$ARGV[0];\n";
}
print $dot . "}";
}
然後運行以下把輸出到一個PNG圖像:
$ t=build; perl dependencies.pl $t | tred | dot -T png > $t.png
或ASCII文本:
$ t=build; perl dependencies.pl $t | tred | graph-easy > $t.txt
感謝詳細的答覆 – LazerBanana