2014-10-27 129 views
0

項目,我有一個搖籃多項目構建,看起來像這樣:配置在子目錄

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" } 
} 

回答

0

添加這的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} } }