【问题标题】:Gradle compile project failing with spring boot pluginGradle 编译项目使用 Spring Boot 插件失败
【发布时间】:2019-09-24 09:09:53
【问题描述】:

我试图了解为什么将 Gradle 4.x Spring Boot 插件添加到 Gradle 依赖项会导致我的构建失败。基于这个link的设置:

Project
  |--build.gradle //plugin here is fine
  |--settings.gradle
Dependency
  |--build.gradle //plugin here causes failure
  |--com.activemq.common //dependency I want to import

如果我有的话,在 Dependency/build.gradle 中:

//Dependency/build.gradle
apply plugin: 'java'

gradle build --> 按预期工作

现在,如果我添加 Spring Boot 插件,它会失败:

//Dependency/build.gradle
apply plugin: 'java'
apply plugin: 'org.springframework.boot'

repositories {
    mavenCentral()
}

我收到一个错误,它找不到依赖项下的包

gradle build --> Application.java:5: error: package com.activemq.common 确实 不存在

我可以删除插件,但依赖也是 Spring Boot,所以我想拥有它。

我尝试做 gradle build --info,但没有看到任何有用的东西。还尝试了 Gradle 5,但出现了我仍在调查的不同错误。 谁能解释一下为什么添加插件会导致这个失败?

【问题讨论】:

  • 你能显示build.gradle吗
  • spring boot 插件的目标是生成一个包含spring boot 应用程序及其所有依赖项的可执行jar 文件。据我了解,Dependency 只是您要在根项目中使用的库。所以它不应该应用引导插件。它应该简单地应用 java-library 插件。如果你想使用 spring boot BOM 来获取 boot 依赖版本,那么请看docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/…
  • @JBNizet - 这似乎没有帮助。我可能会像这里所说的那样内联库,但是我必须每次都复制那个文件夹,这感觉很尴尬。 spring.io/guides/gs/multi-module

标签: java spring-boot gradle


【解决方案1】:

看来我需要解决两件事

  1. 我不能像上面那样使用典型的 gradle.build,但必须使用一个特殊的“Spring Boot 的独立依赖管理”版本,它使用“mavenBom”——这个例子对我有用https://github.com/spring-guides/gs-multi-module/blob/master/complete/library/build.gradle

  2. 我也不能在 Project/Dependency 文件夹中使用 settings.gradle,而是需要将 settings.gradle 放在顶层,如下所示: https://github.com/spring-guides/gs-multi-module/blob/master/complete/settings.gradle

这不起作用:

Project
  |--settings.gradle
Dependency
  |--settings.gradle

这行得通:

Project
  |
Dependency
  |
settings.gradle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 2019-07-22
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多