How do I define a variable for the dependency version in Gradle

前端 未结 8 1990
心在旅途
心在旅途 2020-12-25 10:00

I am currently trying to migrate a Maven project to Gradle

In my Maven version I have the dependency versions all listed out l

8条回答
  •  青春惊慌失措
    2020-12-25 10:10

    Adding to Vikas Sachdeva's answer:

    It's not worked for me in that way on my subproject. The Gradle throws an error 'Could not find org.springframework:spring-context:$springVersion'. Finally, I solved my problem by adding the plus sign.

    for example:

    root gradle.properties:

    springVersion = '5.0.3.RELEASE'
    

    root build.gradle

    dependencies {
        compile  "org.springframework:spring-context:${springVersion}"
    }
    

    subproject build.gradle

    dependencies {
        compile  "org.springframework:spring-context:" + springVersion
    }
    

    Note: my gradle version is 5.4.1

    or you can using the plugin manage your dependency version.

    io.spring.dependency-management

    Refs: https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/

提交回复
热议问题