Gradle boot从多模块项目中的父文件夹运行

jsc*_*man 4 gradle spring-boot

我有我的Gradle 项目,它有 2 个模块:项目 A项目 B,后者依赖于前者。请注意,这两个项目都是Spring Boot应用程序,所以当我执行时gradle bootRun从各自的目录执行时,它们会正常启动。

问题是我想在执行时从父目录启动项目 A的服务gradle bootRun,并且它正在启动项目 B。看来我错过了一些Gradle配置。

build.gradle(项目A)

group = 'com.oni'
version = '0.0.2-SNAPSHOT'
sourceCompatibility = 1.8



dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-mongodb")
    compile 'org.javassist:javassist:3.18.2-GA'
    testCompile("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
}
Run Code Online (Sandbox Code Playgroud)

build.gradle(项目B)

group = 'com.oni'
version = '0.0.2-SNAPSHOT'
sourceCompatibility = 1.8

dependencies {
    def withoutInflux = { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-data-mongodb' }

    compile project(':projectA'), withoutInflux
    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.7'
}
Run Code Online (Sandbox Code Playgroud)

构建.gradle(父级)

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}


subprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'


    repositories {
        mavenCentral()
//        mavenLocal()
    }


    dependencies {
        implementation('org.springframework.boot:spring-boot-starter')
        testImplementation('org.springframework.boot:spring-boot-starter-test')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.springframework.boot:spring-boot-starter-actuator')
        compile('org.influxdb:influxdb-java')
        compile('org.mockito:mockito-core')
        compile('ma.glasnost.orika:orika-core:1.4.2')
        compile 'com.google.guava:guava-annotations:r03'
    }
}
Run Code Online (Sandbox Code Playgroud)

设置.gradle(父级)

rootProject.name = 'project'


include 'projectA'
include 'projectB'
Run Code Online (Sandbox Code Playgroud)

提前致谢。

小智 6

您可以通过使用来运行它

./gradlew :projectA:bootRun
./gradlew :projectB:bootRun
Run Code Online (Sandbox Code Playgroud)