Gradle构建在父gradle

Gradle构建在父gradle

本文介绍了Gradle构建在父gradle.properties文件中找不到属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个项目gradle构建,并且我试图通过gradle.properties来外部化依赖项版本。不幸的是,子项目无法在父gradle.properties中找到属性。

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

所以在父gradle.properties中,我有:

So in parent gradle.properties I have :

SPRING_VERSION=3.2.0.RELEASE

在父版本中。 gradle我有

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.

还在父文件中,我有settings.gradle,它指定了:

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

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

项目结构

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

感谢帮助

w

推荐答案

在Groovy中,双引号字符串支持字符串插值,而单引号字符串则不支持。显然,您在子项目中错误地使用了单引号String。结果,Gradle一直在搜索一个字面名为 $ SPRING_VERSION 的版本,当然找不到它。

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.

这篇关于Gradle构建在父gradle.properties文件中找不到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:51