java Gradle“构建”任务究竟包括什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44324060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does Gradle 'build' task include exactly
提问by LazerBanana
I have searched on Gradle docs and on the stackoverflow and some other places but I can't find information about what is bundled in this task in depth, or I missed it, if so please point me to the direction.
我已经在 Gradle 文档和 stackoverflow 以及其他一些地方进行了搜索,但是我找不到有关此任务中捆绑的内容的深入信息,或者我错过了它,如果是这样,请指出方向。
- It comes from
java-base
plugin, right? - Running
gradle -q tasks
doesn't say much about it.
- 它来自
java-base
插件,对吧? - 跑步
gradle -q tasks
并没有说太多。
build - Assembles and tests this project.
build - 组装和测试这个项目。
Running
gradle help --task build
shows detailed info, ok - but it show where the task is used, in which groups is included, type of a task, and paths.I have tried to track manually what does comes with it, and noticed, compile, test etc tasks.
运行
gradle help --task build
显示详细信息,好的 - 但它显示任务的使用位置,包含的组,任务类型和路径。我尝试手动跟踪它附带的内容,并注意到、编译、测试等任务。
I would like to know what exactly comes from Gradle build task, what are the task dependencies.
我想知道 Gradle 构建任务究竟来自什么,任务依赖项是什么。
采纳答案by lance-java
You can use the Gradle Task Tree Pluginto see the task dependencies
可以使用Gradle Task Tree Plugin查看任务依赖
eg:
例如:
plugins {
id "com.dorongold.task-tree" version "1.3.1"
}
Then run
然后运行
gradle build taskTree
Output
输出
:build
+--- :assemble
| \--- :jar
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :check
\--- :test
+--- :classes
| +--- :compileJava
| \--- :processResources
\--- :testClasses
+--- :compileTestJava
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :processTestResources
回答by Eduardo
回答by Johnny Baloney
Starting with version 4.0you have to run gradle build --console=plain
to see the complete list of task dependencies.
从4.0 版开始,您必须运行gradle build --console=plain
才能查看任务依赖项的完整列表。
If you use java-base
plugin then the dependencies are:
如果您使用java-base
插件,则依赖项是:
$ gradle build --console=plain
:assemble
:check
:build
If you use java
(which automatically appliesjava-base
) then the dependencies are:
如果您使用java
(自动应用java-base
),那么依赖项是:
$ gradle build --console=plain
:compileJava
:processResources
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build
In order to see the exact chain of dependencies shown in the pictures above I used a little Perl helper that can be run inside of a Gradle project. It produces a dotstring describing dependency graph:
为了查看上图中显示的确切依赖链,我使用了一个可以在 Gradle 项目中运行的小 Perl 助手。它产生一个描述依赖图的点串:
#/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 . "}";
}
Then run the following to turn the output into a PNG image:
然后运行以下命令将输出转换为 PNG 图像:
$ t=build; perl dependencies.pl $t | tred | dot -T png > $t.png
or ASCII text:
或 ASCII 文本:
$ t=build; perl dependencies.pl $t | tred | graph-easy > $t.txt