![](/img/trans.png)
[英]Launch multiple Gradle “spring-boot” plugin “bootRun” tasks in parallel
[英]Gradle multiple subproject with different spring boot plugin
我有多個項目構建結構,並且Spring Boot從父級應用到所有子項目。 這是父build.gradle
buildscript {
repositories {
maven {
url 'http://someurl.com/repository/MavenRepositoryGroup/'
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
..
..
..
}
}
在多個子項目中,我需要僅將一個子項目升級到spring boot 2版本。 怎么做?
這很容易,只需在使用子程序的子項目中直接聲明它們即可。 順便說一句,考慮使用新的plugins
DSL而不是apply
。 看看我為您創建的演示項目 。 以下是最有趣的部分:
settings.gradle :
rootProject.name = "so53381565"
enableFeaturePreview("IMPROVED_POM_SUPPORT")
include(":a")
include(":b")
include(":c")
build.gradle :
subprojects {
apply plugin: "java"
repositories {
jcenter()
}
}
wrapper {
gradleVersion = "4.10.2"
distributionType = Wrapper.DistributionType.ALL
}
a / build.gradle :
plugins {
id "org.springframework.boot" version "1.5.8.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter"
}
b / build.gradle :
plugins {
id "org.springframework.boot" version "1.5.17.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter"
}
c / build.gradle :
plugins {
id "org.springframework.boot" version "2.0.6.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-dependencies:2.0.6.RELEASE"
implementation "org.springframework.boot:spring-boot-starter"
}
App.java :
@SpringBootApplication
public class App implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println(SpringVersion.getVersion());
}
}
App.java
在所有三個子項目中都相同。 執行./gradlew clean :a:bootRun :b:bootRun :c:bootRun
將輸出如下內容:
…
4.3.12.RELEASE
…
4.3.20.RELEASE
…
5.0.10.RELEASE
…
如您所見,您正在三個不同的子項目中使用三個不同的Spring。
編輯
首先,您仍然可以使用apply
,只需將它們放在子項目中即可。
其次,您可以通過在settings.gradle
添加 pluginManagement
塊(甚至是未在Gradle的插件存儲庫中發布的那些plugins
來使用具有自己的存儲庫和依賴項的插件(這是我項目中的Kotlin DSL):
pluginManagement {
repositories {
gradlePluginPortal()
add(jcenter())
add(maven("http://my.jfrog.io"))
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "by.dev.madhead.some-plugin") {
useModule("by.dev.madhead:some-gradle-plugin:${requested.version}")
}
}
}
}
現在我能夠使用by.dev.madhead.some-plugin
的plugins
整個項目DSL:
plugins {
id("by.dev.madhead.some-plugin").version("42")
}
它會被by.dev.madhead:some-gradle-plugin:42
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.