Gradle多模块依赖项

时间:2017-05-17 22:25:25

标签: java android spring gradle spring-boot

我有一个Spring Boot多模块Gradle应用程序。

所有内容都在本地构建和运行而没有问题,但是我的子项目输出的JAR不包含任何必需的依赖项,奇怪的是生成的清单只包含Manifest-Version: 1.0

我已经尝试了几乎所有我能想到的不同组合,但现在已经没有想法了!

这是我的root build.gradle:

buildscript {
    ext {
        springBootVersion = "1.5.3.RELEASE"
    }
    repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("io.spring.gradle:dependency-management-plugin:1.0.2.RELEASE")
        classpath("de.thetaphi:forbiddenapis:2.3")
        classpath("com.diffplug.spotless:spotless-plugin-gradle:3.3.2")
    }
}

subprojects {

    apply plugin: "java"
    apply plugin: "idea"
    apply plugin: "com.diffplug.gradle.spotless"
    apply plugin: "de.thetaphi.forbiddenapis"
    apply plugin: "io.spring.dependency-management"
    apply plugin: "org.springframework.boot"

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenCentral()
        flatDir {
            dirs "libs"
        }
    }

    jar {
        baseName = "app"
        version = "0.0.1-SNAPSHOT"
    }

   spotless {
       java {
           googleJavaFormat()
       }
   }

    idea {
        module {
            inheritOutputDirs = false
            outputDir = file("$buildDir/classes/main/")
        }
    }

    task dev {
        doLast {
            bootRun.systemProperty "spring.profiles.active", "dev"
        }
    }

    bootRepackage {
        enabled = false
    }

    bootRun {
        addResources = true
        systemProperties = System.properties
    }

    forbiddenApis {
        // https://github.com/policeman-tools/forbidden-apis/wiki/GradleUsage
        bundledSignatures = [ "jdk-unsafe", "jdk-deprecated", "jdk-non-portable" ]
        signaturesFiles = files("../forbidden_signatures.txt")
        ignoreFailures = false
    }

    dependencies {
        compile("org.springframework.boot:spring-boot-starter") {
            exclude group: "org.flywaydb", module: "flyway-core"
        }
        compile("org.springframework.boot:spring-boot-devtools")

        compile("com.google.guava:guava:21.0")
        compile("org.apache.commons:commons-lang3:3.5")
        compile("org.projectlombok:lombok")

        testCompile("org.springframework.boot:spring-boot-starter-test")
        testCompile("com.h2database:h2")
    }

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

    test {
        testLogging {
            events "failed"
            exceptionFormat "full"
        }
    }
}

我的一个子项目的gradle.build:

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath("com.moowork.gradle:gradle-node-plugin:1.1.1")
    }
}

apply plugin: "com.moowork.node"

dependencies {
    compile project(":core")
    compile project(":search")

    // Spring projects
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.security:spring-security-web")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-mail")

    // Thymeleaf
    compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
    compile("it.ozimov:spring-boot-thymeleaf-email:0.5.3")

    // Email
    compile("com.sendinblue:sendinblue:2.0")
    compile("com.icegreen:greenmail-spring:1.5.3")

    // DB
    compile("org.postgresql:postgresql:42.0.0")
    compile("org.flywaydb:flyway-core:4.1.2")
}

ext["thymeleaf.version"] = "3.0.5.RELEASE"
ext["thymeleaf-layout-dialect.version"] = "2.2.1"

node {
    version = "7.10.0"
    download = true
}

npmInstall.args = ['--silent']

// make sure node and build dependencies are installed before calling webpack
npm_run_build.dependsOn "npmInstall"

npm_run_build.dependsOn npm_run_lint

// make sure webpack generates assets for the build
processResources.dependsOn npm_run_build

非常感谢任何帮助或想法!

谢谢

1 个答案:

答案 0 :(得分:0)

好哇!

事实证明问题是:

bootRepackage {
    enabled = false
}

它被错误地应用于所有子项目。相反,它只需要不是启动应用程序的子项目 - 例如共享模块。

subProjects任务中删除此配置并仅将其添加到共享模块后,编译问题就消失了。

希望这有助于其他人:)