gpt4 book ai didi

java - 解决依赖关系后使Zip任务运行

转载 作者:行者123 更新时间:2023-12-03 04:01:20 25 4
gpt4 key购买 nike

我有一个子项目B,它依赖于其他子项目A。我已经将子项目A包含在子项目B的“build.gradle”中。

dependencies {
compile project(':projA')
}

我的两个子项目A和B在发布时都会创建一个 bundle 的zip。我想将属于子项目A的某些文件复制到子项目B,而无需再次引用子项目A。根项目的“build.gradle”脚本包含以下任务。
subprojects {
task bundleBin(type: Zip) {
description 'Creates "bin.zip" bundle.'

dependsOn build

def bundleName = "$outputName-bin"

/// THIS DOES NOT WORK
def deps = configurations.runtime.getAllDependencies().findAll { it instanceof ProjectDependency }
println "GROOT: " + deps

into("$bundleName/dep") {
/// THE LINE BELOW WORKS
/// I do not want a fixed reference since it is already defined in each subproject's "build.gradle" file
//from project(':projA').file('conf/')
for (dep in deps) {
def proj = dep.getDependencyProject()
from (proj.projectDir) {
include "conf/"
include "scripts/"
}
}
}

into(bundleName) {
from(".") {
include "conf/"
include "scripts/"
}
}

into("$bundleName/lib") {
from configurations.runtime.allArtifacts.files
from configurations.runtime
}

archiveName = "${bundleName}.zip"
}
}

我不想再次引用子项目A的原因是因为我有一个依赖于某些其他项目的项目列表,并且我不想单独维护每个依赖项。

我想要上面的脚本做的是,当为B运行时,在A和B中使用“conf /”和“scripts /”,并将它们放在“B-bin.zip”中。而如果我有一个依赖于A和B的子项目C,则上面的脚本将在A,B和C中使用“conf /”和“scripts /”,并将它们放在“C-bin.zip”中。

运行上述脚本时,除非将其封装在“doLast”中,否则不会显示依赖项。但是,这在Zip任务中不起作用。

我的问题是,我该如何解决?

最佳答案

您需要确保首先解决配置。
您可以使用.resolvedConfiguration来做到这一点,但请注意,在配置时进行解析意味着无论调用什么任务都将完成此操作,因此应避免。
This anwser建议您可以通过直接遍历配置来实现相同目的。

仅当您的任务即将执行时,才可以使用gradle.taskGraph.whenReady延迟解析配置。您仍然可以在那里配置任务。

关于java - 解决依赖关系后使Zip任务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40150973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com