配置在子目录

问题描述:

项目,我有一个摇篮多项目构建,看起来像这样:配置在子目录

rootProject 
    build.gradle 
    settings.gradle 
    shared/ 
     SharedLib 
     SharedLib2 
    plugins/ 
     FirstPlugin 
     SecondPlugin 

我想在目录shared作为依赖添加的所有项目,所有项目在plugins

更一般地说:如何通过目录配置子项目?


内容settings.gradle的:

include 'plugins:FirstPlugin', 'plugins:SecondPlugin', 'shared:SharedLib', 'shared:SharedLib2' 

的build.gradle内容:

task wrapper(type: Wrapper) { gradleVersion = "2.1" } 

allprojects{ apply plugin:"java" } 
subprojects { 
    group = "eu.test.myGroup" 
    repositories { mavenCentral() } 
    dependencies { testCompile "junit:junit:4.11" } 
} 

添加这的build.gradle做什么,我想实现:

// Define what's a plugin and what's a shared library by directory paths. 
// Ignore empty projects 
def plugins = subprojects.findAll{ it.path.contains("plugins") && hasSrc(it) } 
def sharedLibs = subprojects.findAll{ it.path.contains("shared") && hasSrc(it)} 

/** Checks whether a project has a source directory */ 
def hasSrc(proj){ 
    return new File(proj.projectDir, "src").exists() 
} 

// Configure the plugins to depend on the shared libraries at compile time 
configure(plugins) { dependencies { sharedLibs.each{compile it} } }