在Gradle的buildSrc目录中指定Spring Boot的版本

如果你尝试了一下,它只是略微运动了一下,所以如果实际使用的话,请注意。

使用gradle init生成具有子项目的项目时,gradle至少6.8.3版本会将共同定义保存在插件中(详细信息请参见https://docs.gradle.org/6.8.3/samples/sample_building_java_applications_multi_project.html)。以前的做法是使用allprojects或subprojects,通过搜索可以找到很多类似的示例。不过,这个示例似乎还比较少见。

关于在buildSrc目录下的build.gradle文件中指定spring-boot的(bom的)版本的方法。

可以按照以下方式指定spring-boot-dependencies。

dependencies {
   implementation platform("org.springframework.boot:spring-boot-dependencies:2.4.4");
  ...

事情不尽如人意

起初我认为可以通过在xxx.java-common-conventions.gradle中定义spring-boot插件来解决这个问题。

plugins {
  id 'org.springframework.boot' version '2.4.4'
  ...

然而,这会产生一个错误。这个插件会预编译,因此无法写入包含在其中的插件版本(不太清楚)。

* What went wrong:
Invalid plugin request [id: 'org.springframework.boot', version: '2.4.4']. Plugin requests from precompiled scripts 
must not include a version number. Please remove the version from the offending request and make sure the module
containing the requested plugin 'org.springframework.boot' is an implementation dependency
bannerAds