【问题标题】:Gradle spring boot with assembly module带装配模块的 Gradle 弹簧靴
【发布时间】:2017-04-30 10:51:25
【问题描述】:

我是 Gradle 新手,遇到了一个问题(使用 Gradle 2.14)

我的项目有 3 个子项目:程序集、sprinBootProject、E2E
组装模块负责压缩 Spring Boot 应用程序的 jar 以及属性文件。
E2E 模块是一个“端到端”测试模块,用于测试 Spring Boot 应用程序。

我在 assembly/build.gradle 中使用分发插件,如下所示:

apply plugin: 'distribution'

distributions {
    main {
        baseName "project-assembly"
        contents{
            from project(':springBootProject').fileTree(dir: 'build/libs', include: ['*.jar'])
            from project(':springBootProject').fileTree(dir: 'build/resources/main', includes: ['*.properties', 'conf/*.properties'])
        }
    }
}

但我需要确保 springBootProject 将在程序集子项目之前进行评估,所以我像这样使用了 dependsOn:

distZip.dependsOn(':springBootProject:build')

当我添加这一行时,我看到 E2E 模块在 compileTestJava 任务中失败,所以这一行影响了 Spring Boot 应用程序的生成方式(我认为)

E2E/build.gradle:

dependencies {
    testCompile project(":springBootProject")
}

所以我的问题是我做得对吗?为什么当我添加dependsOn行时,E2E模块会受到影响,我如何强制Gradle在组装模块之前评估spring boot应用程序?

【问题讨论】:

标签: java gradle spring-boot


【解决方案1】:

我想通了。 Gradle 将按字母顺序评估模块
所以评估将是:组装 -> E2E -> springBootProject
将此行添加到 assembly/build.gradle 时:

distZip.dependsOn(':springBootProject:build')

评估顺序改为:组装 -> springBootProject -> E2E

现在在'springBootProject'模块中,我使用spring boot插件来生成一个可执行jar,这个可执行jar是由任务生成的:springBootProject:bootRepackage使用由:springBootProject:jar任务生成的jar并转换它可以执行。

现在因为“E2E”模块依赖于“springBootProject”,它将使用它的 jar,但现在这个 jar 是可执行的,因此我在“E2E”中遇到了编译错误。

所以我必须确保“E2E”模块获取原始 jar 而不是可执行文件。 所以我在 springBootProject/build.gradle 中添加了这一行:

bootRepackage.mustRunAfter(':E2E:test')

这似乎解决了问题

【讨论】:

    猜你喜欢
    • 2018-11-22
    • 2018-02-14
    • 1970-01-01
    • 2014-06-27
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2021-02-16
    相关资源
    最近更新 更多