[英]creating springboot gradle multi-module library project using plugins DSL and a convention plugin that reside in buildSrc
I am trying to build multi module gradle library.我正在尝试构建多模块 gradle 库。 I am trying to follow what I read in offical documentation.我正在尝试按照我在官方文档中阅读的内容进行操作。 I am working in company which has its own nexus repository for spring and other libraries我在公司工作,该公司拥有自己的 spring 和其他图书馆的关系存储库
My project structure is as follows multi-project我的项目结构如下
├── libA ├── libA
│ └── build.gradle │ └── build.gradle
├── libB ├── libB
│ └── build.gradle │ └── build.gradle
├── buildSrc ├── buildSrc
│ └── build.gradle │ └── build.gradle
└── main/src/groovy └── main/src/groovy
└────────multiproject.common-conventions.gradle └──────────multiproject.common-conventions.gradle
│ └── settings.gradle │ └── 设置.gradle
The project involves using spring boot for different library, and the dependencies are almost the same.项目涉及到不同库使用spring启动,依赖几乎相同。 Here was my attempt that is not working这是我的尝试,但没有用
buildSrc/build.gradle buildSrc/build.gradle
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal()
}
buildSrc/multiproject.common-conventions.gradle 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()
}
now I try to use above plugin in one sub modules, let say libA libA/build.gradle现在我尝试在一个子模块中使用上面的插件,比如说 libA libA/build.gradle
plugins {
id("multiproject.common-conventions")
id 'org.springframework.boot' version
}
I get the following exception我得到以下异常
org.gradle.api.plugins.UnknownPluginException: Plugin with id 'org.springframework.boot' not found.
when I add the version to 2.6.4 I get 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.
当我将版本添加到 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.
How can I setup multi module gradle library to use common-conventions plugin using the buildSrc folder, and the plugins DSL?如何使用 buildSrc 文件夹和插件 DSL 设置多模块 gradle 库以使用通用约定插件? I am using gradle 7.3 version.我正在使用 gradle 7.3 版本。
Have a look at this section of Gradle's doc https://docs.gradle.org/current/userguide/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins .查看 Gradle 文档https://docs.gradle.org/current/userguide/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins的这一部分。 As stated there, in order to apply an external plugin (spring-boot-gradle-plugin in your case) in a precompiled script plugin (your multiproject.common-conventions.gradle), it has to be added to the plugin project's implementation classpath in the plugin's build file (you're buildSrc/build.gradle file)如那里所述,为了在预编译脚本插件(您的 multiproject.common-conventions.gradle)中应用外部插件(在您的情况下为 spring-boot-gradle-plugin),必须将其添加到插件项目的实现类路径中在插件的构建文件中(你是 buildSrc/build.gradle 文件)
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.