【问题标题】:Gradle dependency management to force versionGradle 依赖管理强制版本
【发布时间】:2019-12-29 08:32:30
【问题描述】:

在 Maven <dependencyManagement> 标签中进行依赖管理的最佳方法是什么?

我在网上做了一些研究,发现有几个选择:

【问题讨论】:

    标签: gradle


    【解决方案1】:

    使用 Gradle 对导入 BOM 的原生支持:

    来自文档here

    dependencies {
        // import a BOM
        implementation(platform("org.springframework.boot:spring-boot-dependencies:2.1.7.RELEASE"))
    
        // define dependencies without versions
        implementation("com.google.code.gson:gson")
        implementation("dom4j:dom4j")
    
        // import a BOM for test dependencies
        testImplementation(platform("org.junit:junit-bom:5.5.1"))
    
        // define dependency without versions
        testImplementation("org.junit.jupiter:junit-jupiter")
    }
    

    我建议观看Managing Dependencies for Spring Projects with Gradle by Jenn Strater and Andy Wilkinson,了解 Spring 的依赖管理插件存在的原因以及插件本身和 Gradle 的发展方向。

    【讨论】:

    • 谢谢@Francisco,我去看看
    【解决方案2】:

    我是用这种方式强制版本的:

    configurations.all {
            
            resolutionStrategy {
                eachDependency { DependencyResolveDetails details ->
                    if (details.requested.group == 'redis.clients') {
                        details.useVersion "3.0.1"
                    }
                    if (details.requested.group == 'com.github.jsqlparser') {
                        details.useVersion "2.1"
                    }
                    if (details.requested.group == 'com.squareup.okhttp3') {
                        details.useVersion "4.0.0"
                    }
                    if (details.requested.group == 'com.github.pagehelper' && !details.requested.name.contains('spring-boot')) {
                        
                        details.useVersion("5.1.11")
                    }
                }
            }
        }
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-30
      • 2019-04-07
      • 2013-06-15
      • 2017-08-21
      • 1970-01-01
      • 2021-07-11
      • 2015-10-17
      相关资源
      最近更新 更多