简体   繁体   English

Gradle spring 依赖管理插件和发布库

[英]Gradle spring dependency management plugin and publishing the library

Im have my library, for help me with spring stuff, build.gradle looks like我有我的图书馆,为了帮助我处理 spring 的东西, build.gradle看起来像

plugins {
    id 'java-library'
    id 'maven-publish'
    id "io.spring.dependency-management" version "1.0.11.RELEASE"
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.boot:spring-boot-dependencies:2.7.0'
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}

publishing {
    // Default maven publish settings
}

When publishing, Gradle generates .module files, and then if the library is used by gradle, it prioritizes .module files over .pom files发布时,Gradle 会生成.module文件,然后如果该库被 gradle 使用,它会将.module文件优先于.pom文件

The problem is that no dependencyManagement information is written to the .module file, and so when I try to use the library in another project, I get问题是没有将依赖管理信息写入.module文件,因此当我尝试在另一个项目中使用该库时,我得到

Could not determine the dependencies of task ':shadowJar'.
> Could not resolve all dependencies for configuration ':runtimeClasspath'.
   > Could not find org.springframework.boot:spring-boot-starter-data-mongodb:.
     Required by:
         project : > project :database > ru.spliterash:spcore-spring-database-mongo:1.0.0-SNAPSHOT:20220714.235637-1

I can solve this problem by disabling the generation of .module files, and gradle will have to use a pom file in which the version is written, but maybe if there is some more correct solution, because it seems to me that this is not entirely correct我可以通过禁用.module文件的生成来解决这个问题,并且 gradle 将不得不使用编写版本的 pom 文件,但也许如果有一些更正确的解决方案,因为在我看来这并不完全正确的

I have found a solution to the problem.我找到了解决问题的方法。

In new versions of gradle, this appeared as a built-in solution, and now spring dependency management plugin is not needed.在新版本的 gradle 中,这是作为内置解决方案出现的,现在不需要 spring 依赖管理插件。 In order to add a maven bom, it is enough just to write, and it will be correctly entered into the module file为了添加一个maven bom,写就够了,会正确进入module文件

dependencies {
    implementation(platform('org.springframework.boot:spring-boot-dependencies:2.7.0'))
    implementation(platform('org.springframework.cloud:spring-cloud-dependencies:2021.0.2'))

    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM