我正在尝试关注this Spring Boot/Vaadin guide,但是,我正在使用Gradle,不是 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>
但是,我看不到通过Gradle提供的dependencyManagement
任务。所以我问:如何在“ Gradle land”中复制与上面的<dependencyManagement/>
XML元素相同的行为?
dependencyManagement {
imports {
mavenBom 'com.vaadin:vaadin-bom:10.0.11'
}
}
唯一的问题是,当我将其添加到build.gradle
并运行./gradlew clean
时,出现以下Gradle错误:
“ 找不到参数的方法dependencyManagement()... ”
答案 0 :(得分:1)
这应该给您一个有效的版本:
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'
}
运行./gradlew dependencies --configuration compileClasspath
来查看Java编译类路径上现在所有依赖项都可用。
经过编辑以回答评论中的问题:确实,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中找到原因,其中定义了版本1.2.6
,作者还提到了原因:“传递Webjar依赖关系,在此定义为可重复的构建”