【发布时间】:2013-02-23 01:51:34
【问题描述】:
我有一个 Gradle 构建,它可以生成我的产品的主要可交付工件(安装程序)。对此进行建模的 Gradle 项目在不同的配置中具有许多不同的依赖项。其中许多依赖项依赖于外部模块的默认配置,其中一些模块具有 testResults 配置,其中包含测试任务的(压缩)结果。
重要的是,所有依赖项的测试结果(如果存在)作为主要产品构建的工件发布(用作测试发生并成功的证据)。如果它们不存在,这不是问题。
我尝试通过迭代产品构建的所有配置、迭代每个配置中的依赖项并在模块的testResults 配置上添加以编程方式创建的依赖项(在为此目的创建的新配置中)来做到这一点。
换句话说,我创建这样的依赖项:
def processDependencyForTests( Dependency dependency ) {
def testResultsDependency = [
'group' : dependency.group,
'name' : dependency.name,
'version' : dependency.version,
'configuration' : 'testResults'
]
project.dependencies.add 'allTestResults', testResultsDependency
这可以很好地填充该配置,但是当然,当我尝试对其进行任何操作时,当我第一次遇到对实际上没有具有 @987654324 的模块的依赖时,它会失败@配置:
def resolvedConfiguration = configurations.allTestResults.resolvedConfiguration
结果如下:
Build file 'C:\myproduct\build.gradle' line: 353
* What went wrong:
Execution failed for task ':myproduct:createBuildRecord'.
> Could not resolve all dependencies for configuration ':myproduct:allTestResults'.
> Module version group:mygroup, module:myproduct, version:1.2.3.4, configuration:allTestResults declares a dependency on configuration 'testResults' which is not declared in the module descriptor for group:mygroup, module:mymodule, version:1.0
以声明方式显式列出依赖项并不实际,因为我希望它们源自“产品项目具有的任何真实依赖项”。
如何确保此类预期缺失的配置不会破坏我的构建?我认为与宽松配置有关的事情可能是答案,但我什至还没有走到这一步(据我所知,我需要先得到一个ResolvedConfiguration)。或者,如果我这样做的方式很疯狂,那么实现这一点的更自然的 Gradle 习惯用法是什么?
【问题讨论】:
-
您找到处理缺失配置的解决方案了吗?
标签: gradle