繁体   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