简体   繁体   English

Gradle多模块依赖项

[英]Gradle multi module dependencies

I have a Spring Boot multi module Gradle app. 我有一个Spring Boot多模块Gradle应用程序。

Everything builds and runs locally without issue however the JARs being output by my subprojects do not contain any of the required dependencies and strangely the generated manifest contains only Manifest-Version: 1.0 . 所有东西都在本地构建和运行而没有问题,但是我的子项目输出的JAR不包含任何所需的依赖项,奇怪的是生成的清单只包含Manifest-Version: 1.0

I've tried almost all different combinations I can think of but have now run out of ideas! 我已经尝试了几乎所有我能想到的不同组合,但现在已经没有想法!

Here's my root build.gradle: 这是我的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"
        }
    }
}

And the gradle.build for one of my subprojects: 我的一个子项目的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

Any help or ideas would be hugely appreciated! 任何帮助或想法将非常感谢!

Thank you 谢谢

Huzzah! 好哇!

So it turns out the problem was this: 事实证明问题是这样的:

bootRepackage {
    enabled = false
}

It was incorrectly being applied to all sub projects. 它被错误地应用于所有子项目。 Instead, it was only required for sub projects which weren't boot applications - for example shared modules. 相反,只需要不是启动应用程序的子项目 - 例如共享模块。

Once I removed this configuration from the subProjects task and added it to the shared modules only, the compilation problem was gone. subProjects任务中删除此配置并仅将其添加到共享模块后,编译问题就消失了。

Hopefully this helps others :) 希望这有助于其他人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM