您可以生成依賴關係圖不會再次調用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