【发布时间】: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