gradle - 如何在 build.gradle 中嵌入 gradle 的共同价值
问题描述
我在 common.build 中定义了一个公共依赖项,如下所示(Gradle 6.0.1):
ext {
java = [
compileSdkVersion: 1.8,
minSdkVersion : 1.8,
targetSdkVersion : 1.8,
versionCode : 1.8,
]
version = [
mybatisGeneratorCoreVersion : '1.3.7',
itfswMybatisGeneratorPluginVersion: '1.3.8'
]
dependencies = [
mybatisGeneratorCore : "org.mybatis.generator:mybatis-generator-core:${version["mybatisGeneratorCoreVersion"]}",
]
}
并在根项目 build.gradle 中使用,如下所示:
subprojects {
apply from: "${rootProject.projectDir}/common.gradle"
dependencies {
implementation rootProject.ext.dependencies.mybatisGeneratorCore
}
}
并像这样构建项目:
./gradlew clean :soa-illidan-mini:soa-illidan-mini-service:build -x test
并给我这个错误:
~/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dabai/microservice/soa-illidan-mini on master! ⌚ 10:59:03
$ ./gradlew clean :soa-illidan-mini:soa-illidan-mini-service:build -x test
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/dolphin/Library/Mobile Documents/com~apple~CloudDocs/Document/source/dabai/microservice/build.gradle' line: 99
* What went wrong:
A problem occurred evaluating root project 'microservice'.
> Cannot get property 'dependencies' on extra properties extension as it does not exist
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
我跟着网络教程,我应该怎么做才能解决这个问题?
解决方案
将您的应用命令移动到 build.gradle 的根目录,如下所示:
apply from: "${rootProject.projectDir}/common.gradle"
只需将其放在项目配置的顶层即可。有用!
推荐阅读
- windows-10 - 如何在远程 Windows 10 机器上部署
- javascript - 挑战 nodejs CSV 到 JSON 解析问题
- docker - keycloak realm.json 中是否允许使用系统环境变量?
- javascript - 在 Vue.js 组件中放置 PayPal 按钮
- r - 如何在 R 中用特定用户标记相同的值?
- spring-data-redis - ReadFrom.NEAREST 设置无法正常工作
- java - VB.Net 套接字与 Android Socket 通信
- environment-variables - 在mac上删除环境变量
- python - 是否可以在不打开浏览器的情况下在 Python 中播放来自网站的声音/音乐?
- plsql - Apex 20.1 复杂假设情景分析