Gradle exclude plugin in main project for specific subproject(s)

被刻印的时光 ゝ 提交于 2019-12-29 06:38:26

问题


I am working on a larger project that contains many subprojects which are all build with gradle. Generally all projects are java projects, therefore in the main build.gradle script

allprojects {
    apply plugin: 'java'
}

is specified for all projects.

However I need to either remove the plugin for a certain subtree of projects or explicitly exclude the the projects from the plugin.

Heres a rough overview of the project layout

+ Main
+-- javaApplications
+-- javaLibs
+-- Android
+-----AndroidApps
+-----AndroidLibs

Android/* does not need the java plugin. What is the best solution to achieve this? Note: I cannot change the project structure.


回答1:


This should do the trick (when placed in root build.gradle script)

configure(allprojects - project(':Android')) { //or ':Android:AndroidApps' not sure
    println "applying java plugin to $project"
    apply plugin: 'java'  
}



回答2:


You can also do this way:

allprojects {
    if (!it.name.startsWith('Android')) {
        apply plugin: 'java'
    }
}


来源:https://stackoverflow.com/questions/22906806/gradle-exclude-plugin-in-main-project-for-specific-subprojects

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