簡體   English   中英

使用插件 DSL 和駐留在 buildSrc 中的約定插件創建 springboot gradle 多模塊庫項目

[英]creating springboot gradle multi-module library project using plugins DSL and a convention plugin that reside in buildSrc

我正在嘗試構建多模塊 gradle 庫。 我正在嘗試按照我在官方文檔中閱讀的內容進行操作。 我在公司工作,該公司擁有自己的 spring 和其他圖書館的關系存儲庫

我的項目結構如下

├── libA
│ └── build.gradle
├── libB
│ └── build.gradle
├── buildSrc
│ └── build.gradle
└── main/src/groovy
└──────────multiproject.common-conventions.gradle
│ └── 設置.gradle

項目涉及到不同庫使用spring啟動,依賴幾乎相同。 這是我的嘗試,但沒有用

buildSrc/build.gradle

plugins { 
    id 'groovy-gradle-plugin' 
} 

repositories { 
    gradlePluginPortal() 
}

buildSrc/multiproject.common-conventions.gradle

plugins { 
    id 'java-library' 
    id 'maven-publish' 
    id 'org.springframework.boot' 
} 
repositories { 
    mavenCentral()
} 
dependencies { 
     implementation group: 'org.springframework.boot:spring-boot-gradle-plugin'
      implementation 'org.springframework.boot:spring-boot-starter' 
      implementation 'org.springframework.boot:spring-boot-starter-aop' 
      implementation 'org.springframework.ws:spring-ws-core' 
      implementation 'org.apache.httpcomponents:httpclient:4.5.13' 
      implementation 'org.springframework.retry:spring-retry:1.3.1' 
      implementation 'javax.cache:cache-api:1.1.1' 
      implementation 'org.ehcache:ehcache:3.10.0' 
      implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3' 
      testImplementation 'org.springframework.boot:spring-boot-starter-test' 
}

 tasks.named('test') { 
    useJUnitPlatform()
 }

現在我嘗試在一個子模塊中使用上面的插件,比如說 libA libA/build.gradle

plugins { 
id("multiproject.common-conventions")
id 'org.springframework.boot' version
}

我得到以下異常

 org.gradle.api.plugins.UnknownPluginException: Plugin with id 'org.springframework.boot' not found.

當我將版本添加到 2.6.4 時,我收到Invalid plugin request [id: 'org.springframework.boot', version: '2.7.1']. 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. Invalid plugin request [id: 'org.springframework.boot', version: '2.7.1']. 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.

如何使用 buildSrc 文件夾和插件 DSL 設置多模塊 gradle 庫以使用通用約定插件? 我正在使用 gradle 7.3 版本。

查看 Gradle 文檔https://docs.gradle.org/current/userguide/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins的這一部分。 如那里所述,為了在預編譯腳本插件(您的 multiproject.common-conventions.gradle)中應用外部插件(在您的情況下為 spring-boot-gradle-plugin),必須將其添加到插件項目的實現類路徑中在插件的構建文件中(你是 buildSrc/build.gradle 文件)

buildSrc/build.gradle

plugins {
  id 'groovy-gradle-plugin'
}

repositories {
  mavenCentral()
}

dependencies {
  implementation('org.springframework.boot:spring-boot-gradle-plugin:3.0.0')
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM