简体   繁体   中英

Dependency version not resolved from ext block build.gradle

I have added some dependency in my build.gradle file like this

ext {
  boxableVersion = '1.5.bq'
}
dependencies {
  implementation group: "com.github.dhorions", name:'boxable', version:${boxableVersion}
}

This was working seamlessly until I changed my JDK version from 1.8 to 11. Now, When I am trying to build the project, the following error shows up in my build.gradle file

Could not run phased build action using Gradle distribution ' https://services.gradle.org/distributions/gradle-6.0-bin.zip '. Build file '/home/christine/christine/projectsFromGit/pdfcreator/build.gradle' line: 43 A problem occurred evaluating root project 'pdfcreator'. Could not find method $() for arguments [build_4fl1snfk49qgbmumnf1gg989h$_run_closure3$_closure11@d7c9f2a] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

If i give version directly like this, the project is building successfully

implementation group: "com.github.dhorions", name:'boxable', version:'1.5.bq'

How can i give versions externally like I was doing before?

The following syntax version:${boxableVersion} in your dependency declaration is not valid. It's not related to your JDK version, it's just that ${...} means nothing in Gradle DSL or Groovy syntax.

If you want to define version in an 'ext' property, you can then reference this property directly with version: boxableVersion (ext properties are made available directly in the script through the "groovy magic"), or you can use Groovy String interpolation notation (please note the double-quote " )

 version: "${boxableVersion}"

Or, in a simpler way:

implementation "com.github.dhorions:boxable:${boxableVersion}"

Just try:

ext {
    boxableVersion = '1.5.bq'
}
dependencies {
    implementation group: "com.github.dhorions", name:'boxable', version:"${boxableVersion}"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM