Gradle build can not find properties in parent gradle.properties files

淺唱寂寞╮ 提交于 2020-01-05 07:06:28

问题


I have multiple project gradle build and I am trying to externalize dependencies version via gradle.properties. Unfortunately child project can not find properties in parent gradle.properties

So in parent gradle.properties I have :

SPRING_VERSION=3.2.0.RELEASE

in parent build.gradle I have

dependencies {
    compile "org.springframework:spring-webmvc:$SPRING_VERSION"
    ...

and this works fine. But in the child project same thing cause error :

Could not resolve all dependencies for configuration 
Could not find org.springframework:spring-context-support:$SPRING_VERSION.

If I hardcode the version project builds fine.

also in parent file I have settings.gradle which specifies :

include 'projectA','projectB','projectC'

project structure

root
|
\ buildSRC
\ projectA
    |
    \ build.gradle
\ projectB  (build script in parent build.gradle)
\ projectC  (build script in parent build.gradle)
|
|
\ build.gradle
\ gradle.properties
\ settings.gradle

thanks for help

w


回答1:


In Groovy, double-quoted Strings support String interpolation, whereas single-quoted Strings don't. Apparently, you mistakenly used a single-quoted String in the subproject. As a result, Gradle went searching for a version that is literally named $SPRING_VERSION, which of course it didn't find.




回答2:


Unfortunately neither of the other options worked out for me. I had had success referencing the variables in this file using the following.

project.getProperties().SPRING_VERSION

Maybe this will help someone else.




回答3:


Verify if inside your child project you have settings.gradle and if it's there, remove.




回答4:


In projectA-build.gradle you should reference the variables in main gradle.properties with this code:

project.SPRING_VERSION


来源:https://stackoverflow.com/questions/19954564/gradle-build-can-not-find-properties-in-parent-gradle-properties-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!