【问题标题】:How to combine same code of different tasks如何组合不同任务的相同代码
【发布时间】:2015-10-09 06:59:48
【问题描述】:

此问题与Apply same configurations to different tasks有关

在gradle中,我有这样一段配置:

idea {
    module {
        excludeDirs -= file("$buildDir/")
        sourceDirs += file(generatedSrcDir)
    } 
}

我还有另一个用于 Eclipse 的代码。

问题:

idea, eclipse {
    module {
        excludeDirs -= file("$buildDir/")
        sourceDirs += file(generatedSrcDir)
    }
}

这可能吗?

【问题讨论】:

    标签: gradle task build.gradle


    【解决方案1】:

    你需要做的事情会写成如下:

    apply plugin: 'idea'
    apply plugin: 'eclipse'
    
    ext.generatedSrcDir = project.file('.')
    
    [idea, eclipse].each {
        configure(it) {
            module {
                excludeDirs -= file("$buildDir/")
                sourceDirs += file(generatedSrcDir)
            }
        }
    }
    

    但由于eclipse 扩展没有公开module 方法/字段,它不会工作。不幸的是,您需要分别配置ideaeclipseHere 是关于为 eclipse 配置附加源文件夹的问题。

    【讨论】:

    • 是的..你是对的。它不适用于 Eclipse,因为它没有模块。谢谢你的新链接。那是一种新的学习。
    • @smilyface,如果您觉得我的回答对您有帮助,请接受 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 2021-10-27
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多