In gradle, how to use a variable for a plugin version?

前端 未结 4 871
故里飘歌
故里飘歌 2020-12-16 08:52

One of my build scripts imports that nebula plugin:

plugins {
  id \'nebula.ospackage\' version \'3.5.0\'
}

I\'ve been moving all of my ver

4条回答
  •  一整个雨季
    2020-12-16 09:53

    This is an old post, but the bug is still open, and I found this post looking for workarounds.

    It seems you were aware of this already, and actually have BoygeniusDexter's answer, but I think this may help others finding this post like I did. The following workaround is based on the Gradle docs and solved the problem for me:

    buildscript {
        ext {
            springBootVersion = '2.0.4.RELEASE'
        }
        repositories {
            jcenter()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    plugins {
        id 'java'
        // and other plugins
        id 'io.spring.dependency-management' version '1.0.6.RELEASE'
    }
    // but the one with the variable version is applied the old way:
    apply plugin: 'org.springframework.boot'
    
    // We can use the variable in dependencies, too:
    dependencies {
        compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
        // ...
    }
    

提交回复
热议问题