我正在尝试跟随这个 Spring Boot/Vaadin 指南 https://www.baeldung.com/spring-boot-vaadin however我正在使用 Gradle,not Maven.
在该指南的最顶部,他们说使用以下 Maven XML:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>10.0.11</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
但是我没有看到dependencyManagement
可通过 Gradle 执行任务。所以我问:我如何复制与<dependencyManagement/>
上面的 XML 元素位于“Gradle land”中?
更新:当前尝试
dependencyManagement {
imports {
mavenBom 'com.vaadin:vaadin-bom:10.0.11'
}
}
唯一的问题是,当我将它添加到我的build.gradle
然后运行./gradlew clean
我收到以下 Gradle 错误:
"找不到参数的方法 dependencyManagement()..."
这应该会给你一个工作构建:
plugins {
// the Gradle plugin which provides the “dependencyManagement” block
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
// add Java build functionality to be able to follow the Vaadin guide
id 'java'
}
dependencyManagement {
imports {
// the Maven BOM which contains a coherent set of module versions
// for Vaadin dependencies
mavenBom 'com.vaadin:vaadin-bom:10.0.11'
}
}
repositories {
// find dependency modules on Maven Central
mavenCentral()
}
dependencies {
// the dependency module you need according to the Vaadin with
// Spring Boot guide; the version of the module is taken from the
// imported BOM; transitive dependencies are automatically taken
// care of by Gradle (just as with Maven)
compile 'com.vaadin:vaadin-spring-boot-starter'
}
Run ./gradlew dependencies --configuration compileClasspath
可以看到所有依赖项现在都在 Java 编译类路径上可用。
编辑以回复评论中的问题:确实,BOM 的导入导致了一组与没有 BOM 时使用的依赖项略有不同的依赖项。您可以像这样看到依赖关系的差异:
./gradlew dependencies --configuration compileClasspath > with-BOM.txt
- 去除
dependencyManagement
阻止并向单个依赖项添加版本:compile 'com.vaadin:vaadin-spring-boot-starter:10.0.11'
./gradlew dependencies --configuration compileClasspath > without-BOM.txt
diff -u with-BOM.txt without-BOM.txt
您可以看到细微的差异,例如org.webjars.bowergithub.webcomponents:webcomponentsjs:1.2.6
与 BOM 和版本一起使用1.2.2
没有它。其原因可以在the BOM https://repo1.maven.org/maven2/com/vaadin/vaadin-bom/10.0.11/vaadin-bom-10.0.11.pom哪里的版本1.2.6
已定义,作者还提到了其原因:“传递性 webjar 依赖项,在此处定义用于可重复构建”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)