Java Gradle 在主项目中排除特定子项目的插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22906806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle exclude plugin in main project for specific subproject(s)
提问by nfusion
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
我正在处理一个更大的项目,其中包含许多都是用 gradle 构建的子项目。一般所有项目都是java项目,因此在主build.gradle脚本中
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.
Android/* 不需要 java 插件。实现这一目标的最佳解决方案是什么?注意:我无法更改项目结构。
采纳答案by Opal
This should do the trick (when placed in root build.gradle
script)
这应该可以解决问题(当放置在根build.gradle
脚本中时)
configure(allprojects - project(':Android')) { //or ':Android:AndroidApps' not sure
println "applying java plugin to $project"
apply plugin: 'java'
}
回答by Taras Leskiv
You can also do this way:
你也可以这样做:
allprojects {
if (!it.name.startsWith('Android')) {
apply plugin: 'java'
}
}