gpt4 book ai didi

gradle - 如何访问gradle编译依赖项的源工件?

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

我编写了以下任务,该任务为我的每个子项目提取所有编译依赖项,并将它们放在每个子项目目录中:

task exportCompileLibs << {
subprojects.each { iSubProject ->
iSubProject.configurations.findAll{it.name == "compile"}.each{ jConfig ->
println "copying compile libs for ${iSubProject.name}..."
copy {
into "${iSubProject.buildDir}/gradle-lib-export"
from jConfig
eachFile {println it.name}
}
}
}
}

我想扩展它以导出Gradle已经知道的源 Artifact (我可以在缓存目录中看到源jar),我只是不知道如何使用对象模型来获取句柄。他们。

IDEA和Eclipse插件似乎能够做到这一点(它们将它们直接构建的项目文件指向gradle缓存),但是我不知道该怎么做-并查看IDE插件源代码,它看起来...棘手。我希望gradle DSL或API中缺少一些明显的东西。

任何人有任何想法吗?

最佳答案

对于正在寻求至少一个临时解决方案的人,以下内容似乎正在完全满足我目前的需求。

您必须将要导出依赖项的每个项目的IDEA插件应用于build.gradle文件:

apply plugin: 'idea'



然后定义此任务:
task exportDependencies << {
def deps = project.extensions.getByType(IdeaModel).module.resolveDependencies()
copy {
from deps*.classes.file
into "${buildDir}/gradle-lib-export/libs"
}

copy {
from deps*.sources.file
into "${buildDir}/gradle-lib-export/sources"
}
}

这是我的骇客技巧,因此我不必为每个子项目都应用插件:
task exportDependencies(description: "export project dependency jars") << {
subprojects.each { Project iSubProject ->
String target = "${iSubProject.buildDir}/gradle-lib-export"

IdeaPlugin ideaPlugin = new IdeaPlugin()
ideaPlugin.apply(iSubProject)
Set<Dependency> deps = ideaPlugin.model.module.resolveDependencies()

println "exporting dependencies for $iSubProject.name into $target"
copy {
from deps*.classes.file
into "${target}/libs"
eachFile { println "lib -> $it.name" }
}
copy {
from deps*.sources.file
into "${target}/sources"
eachFile{ println "source -> $it.name" }
}
}
}

+10分,因为我的构建任务列表中没有我不想要的东西,-ewwwww有几百万分。

关于gradle - 如何访问gradle编译依赖项的源工件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12338761/

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