Why doesn't this replacement / concatenation string work in Gradle?

In this fragment of the file, the build.gradlefirst link to ${appengineVersion}(line 11) causes an error. But the second link (line 27) works fine. Why is this?

To make it work, I had to explicitly indicate the version number on line 11 ... which means that I will forget to update it next time. How to fix it?

apply plugin: 'war'
apply plugin: 'appengine'

def appengineVersion = "1.9.48"

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "com.google.appengine:gradle-appengine-plugin:${appengineVersion}"
    }
}

war {
    from 'src/main/webUI/app'

    exclude('src/main/webUI/app/node_modules')
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    appengineSdk "com.google.appengine:appengine-java-sdk:${appengineVersion}"

    compile "javax.servlet:servlet-api:2.5"
...
+4
source share
3 answers

Declaring vars at the top level of the project build file does not make them visible to all Gradle blocks. buildscript {}is special, it is evaluated before any other part of the script. You can move the ad to buildscript, although it should make it visible to other blocks:

buildscript {
    def appengineVersion = "1.9.48"
    ...

dependencies {
    appengineSdk "com.google.appengine:appengine-java-sdk:" + appengineVersion
+2

gradle ext. .

:

ext.appengineVersion = "1.9.48"
+2

RaGe:

appengineVersion buildcript ext.

buildscript {
    ext.appengineVersion = "1.9.48"
    repositories {
        mavenCentral()
}
dependencies {
    classpath "com.google.appengine:gradle-appengine-plugin:${appengineVersion}"
    }
}

buildscript, :

dependencies {
    appengineSdk "com.google.appengine:appengine-java-sdk:${appengineVersion}"

    compile "javax.servlet:servlet-api:2.5"
    compile "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}"

. , , 2 , ( ).

+2

Source: https://habr.com/ru/post/1665425/


All Articles