Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在父build.gradle中动态配置任务 我有一个多项目C++ + GADLE构建,它产生了许多库和可执行文件。我正在尝试获取可执行文件(但不是库)子项目,以便使用“指纹”对象进行编译。如果我像这样在单个子项目的build.gradle中使用smth,这会很好: compileMain.doFirst { // code to generate a 'BuildInfo.cpp' from from a template. // embeds name of executable in so has to be generated anew for each exe }_Gradle - Fatal编程技术网

在父build.gradle中动态配置任务 我有一个多项目C++ + GADLE构建,它产生了许多库和可执行文件。我正在尝试获取可执行文件(但不是库)子项目,以便使用“指纹”对象进行编译。如果我像这样在单个子项目的build.gradle中使用smth,这会很好: compileMain.doFirst { // code to generate a 'BuildInfo.cpp' from from a template. // embeds name of executable in so has to be generated anew for each exe }

在父build.gradle中动态配置任务 我有一个多项目C++ + GADLE构建,它产生了许多库和可执行文件。我正在尝试获取可执行文件(但不是库)子项目,以便使用“指纹”对象进行编译。如果我像这样在单个子项目的build.gradle中使用smth,这会很好: compileMain.doFirst { // code to generate a 'BuildInfo.cpp' from from a template. // embeds name of executable in so has to be generated anew for each exe },gradle,Gradle,遵循枯燥的原则,我更愿意在顶级build.gradle中一劳永逸地完成这项工作。这是我的尝试,仅将其应用于使用cpp-exe插件的子项目,如下所示: 唉,这并没有被触发。但是,如果我将smth像这样放在限制较少的配置块中,这表明查询插件的想法应该是可行的: configure(subprojects.findAll{true}){ 任务mydebug您可能在子项目的构建脚本中应用了cpp exe插件。默认情况下,父构建脚本在其子项目之前得到评估,这解释了为什么它找不到任何应用了cpp exe的项

遵循枯燥的原则,我更愿意在顶级
build.gradle
中一劳永逸地完成这项工作。这是我的尝试,仅将其应用于使用
cpp-exe
插件的子项目,如下所示:

唉,这并没有被触发。但是,如果我将smth像这样放在限制较少的
配置
块中,这表明查询插件的想法应该是可行的:

configure(subprojects.findAll{true}){

任务mydebug您可能在子项目的构建脚本中应用了
cpp exe
插件。默认情况下,父构建脚本在其子项目之前得到评估,这解释了为什么它找不到任何应用了
cpp exe
的项目

有几种方法可以解决此问题。一种方法是将特定于cpp exe项目的所有配置(如应用插件和添加操作)移动到同一位置。或者从父构建脚本执行所有此类配置(例如,通过枚举cpp exe子项目并使用单个
configure(cppExeProjects){…}
配置它们),或者将cpp exe特定的配置移动到其自己的构建脚本中(例如
gradle/cpp exe.gradle
),并从所选子项目应用它,如:
apply from:$rootDir/gradle/cpp exe.gradle”


另一个解决方案是更改生成脚本的评估顺序。但我只会将此作为最后手段使用,这里当然没有必要这样做。

Gradle 1.5最近推出,我不确定这是否是一个新功能,但从外观上看,您可以使用afterEvaluate解决此问题。 请参阅中的第53.6.1节

比如:

subprojects {subProject ->
  afterEvaluate {
    if ( subProject.plugins.hasPlugin('cpp-exe')){
      println "Project $subProject.name has plugin cpp-exe"
    }
  }
}

会给你一个开始。

谢谢Peter,使用
apply from:“$rootDir/gradle/cpp exe.gradle”
可以让你享受一顿,可能比原来的提议更优雅。
configure(subprojects.findAll { true }) { 
    task mydebug << {
        if ( project.plugins.hasPlugin( 'cpp-exe' ) ) {
            println ">>> $project.name has it!"
        }
    }
}
subprojects {subProject ->
  afterEvaluate {
    if ( subProject.plugins.hasPlugin('cpp-exe')){
      println "Project $subProject.name has plugin cpp-exe"
    }
  }
}