2017-08-14 43 views
0

我配置了一个gradle项目,以便在我运行./gradlew build时构建子模块,并且它完美无瑕。但是,当我移动到一个子目录,并运行一个子模块像./gradlew :mymodule:build我得到的错误未在根项目'mymodule'中找到项目'mymodule'

Project 'mymodule' not found in root project 'mymodule'. 

我的等级根配置:

group 'com.example.core' 
version '1.0-SNAPSHOT' 

allprojects { 
    apply plugin: 'java' 

    version = '1.0' 
} 

subprojects { 
    repositories { 
     mavenLocal() 
    } 

    dependencyManagement { 
     imports { 
      mavenBom "org.springframework.boot:spring-boot-dependencies:${spring_boot_version}" 
     } 
    } 

    dependencies { 
     compile 'org.springframework.boot:spring-boot-starter-web' 
    } 
} 

project(':mymodule1') { 
    apply plugin: 'application' 

    bootRepackage { 
     mainClass = 'com.example.App' 
    } 

    springBoot { 
     mainClass = 'com.example.App' 
     executable = true 
     buildInfo() 
    } 

    bootRun { 
     addResources = false 
    } 

    task stage(dependsOn: 'bootRepackage') { 
    } 

    dependencies { 
     compile project(':mymodule2') 
    } 

} 

project(':mymodule2') { 
    apply plugin: 'application' 
    // config module 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

buildscript { 
    repositories { 
     // repos 
    } 
    dependencies { 
     // deps 
    } 
} 


defaultTasks 'bootRun' 

repositories { 
    mavenCentral() 
} 

clean { 
    delete "target" 
} 

task cleanResources(type: Delete) { 
    delete 'build/resources' 
} 

task wrapper(type: Wrapper) { 
    gradleVersion = '4.0' 
} 

bootRepackage.enabled = false 

而且我几乎是空的模块的配置辅助模块:

group 'com.example.proj' 
version '1.0-SNAPSHOT' 

我建议一个原因是缺少子模块的运行配置。所以问题是如何指向子模块的build.gralde使用父母的配置?

回答

0

我发现这个问题上运行指定的任务。

问题出在IntelliJ IDEA中项目的错误自动配置。

它配置是这样的:

Alt text

但它需要此

Alt text

0

不用移动到子目录中,从根目录中正确运行./gradlew :mymodule:build

:mymodule前缀已经表明您想(在这里build)为目标的子项目(这里mymodule

+0

什么依赖性和配置?如果我将它们存储在根中,那么我不需要将它们指向子模块。 –

+0

有些配置可以放在根中,其他配置在模块build.gradle中更有意义。依赖关系在每个子模块build.gradle中效果最好,但如果有意义的话,可以在根中找到(再次)。请参阅:https://docs.gradle.org/current/userguide/multi_project_builds.html – jdv

相关问题