您可以生成依赖关系图不会再次调用gradlew
。
真的你想要的是一个插件,其任务是在dependencyReport
之后运行并读取创建的文件。这应该为你做。
apply plugin: 'java'
repositories {
jcenter()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
}
apply plugin: DepReport
class DepReport implements Plugin<Project> {
@Override
void apply(Project project) {
project.pluginManager.apply('project-report')
def reportTask = project.tasks.create('myReport', DepTask) {
group = 'reports'
description = "Create our report"
}
reportTask.dependsOn 'dependencyReport'
reportTask.outputs.upToDateWhen { false }
}
}
class DepTask extends DependencyInsightReportTask {
@OutputFile
def output = new File("$project.buildDir.absolutePath/reports/project", "dependencies.txt")
DepTask() {
configuration = project.configurations.getByName('compile')
}
@Override
@TaskAction
void report() {
def dependencies = output.text.trim()
println "Found dependencies to be $dependencies.chars.length chars long"
// you could print them or manipulate the text as desired but the text is large
}
}
输出:
$ ./gradlew myReport
Configuration on demand is an incubating feature.
:app:dependencyReport
:app:myReport
Found dependencies to be 1301 chars long
BUILD SUCCESSFUL
Total time: 0.712 secs
不知道你要完成的任务。似乎充其量这会导致循环。你想添加一个任务到构建?什么是实际目标? – JBirdVegas
@JBirdVegas嗯,我试图修复一个人写的插件。目标是在发布构建过程中获取项目的所有依赖项的列表,并将其捕获到注释中。我想使用项目对象来获得编译时间构建依赖关系会更好。可能我会在未来增强代码。现在我发现这个问题与一些命令行参数有关。由于代码仅使用来自proc对象的Sysout流并忽略err流,因此未显示错误原因。设置命令行参数后,问题现在已解决。 – prashant
这个代码与项目'app'是否在同一个版本中?在'所显示的代码的运行环境是什么?在插件或其他的'build.gradle'中? – JBirdVegas