Access project extra properties in buildscript closure

前端 未结 3 952
再見小時候
再見小時候 2020-12-01 20:47

I am new to gradle and have some question about project properties.

I need to declare spring boot dependences at multiple locations in my build.gradle and I\'d like

相关标签:
3条回答
  • 2020-12-01 21:25

    Because the buildscript block is evaluated first, before springBootVersion has been defined. Therefore, the variable definition must go in the buildscript block before any other definitions: Source Here

    buildscript {
    
        ext {
            springBootVersion = '1.1.9.RELEASE'
        }
    
        print project.springBootVersion //Will succeed
    
        repositories {
            mavenLocal()
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}")
        }
    }
    
    0 讨论(0)
  • 2020-12-01 21:31

    This will not work.

    First of all buildscript block is evaluated at the very beginning, before any other part of groovy script. Hence, properties defined in ext block just does not exist at that time.

    Secondly, I'm unsure about if exchanging properties between buildscript and other part of script is possible.

    0 讨论(0)
  • 2020-12-01 21:35

    Moving the ext block inside the buildscript block solves the problem for me. Not sure if this is officially supported though, as it's effectively configuring project.ext from the (very special) buildscript block.

    0 讨论(0)
提交回复
热议问题