How to combine same code of different tasks

心不动则不痛 提交于 2020-01-16 18:18:32

问题


This question is related to Apply same configurations to different tasks

In gradle, I have this piece of configuration:

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

I have another one for eclipse with same code.

Question:

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

is this possible ?


回答1:


What you need to do would be written as the following:

apply plugin: 'idea'
apply plugin: 'eclipse'

ext.generatedSrcDir = project.file('.')

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

but since eclipse extension does not expose module method/field it will not work. Unfortunately you need to configure both idea and eclipse separately. Here is a question on configuring additional source folder for eclipse.



来源:https://stackoverflow.com/questions/33031863/how-to-combine-same-code-of-different-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!