Q:

how to get gradle embeded common value in build.gradle

I am define a public dependencies in common.build like this(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"]}",
    ]
}

and using in root project build.gradle like this:
subprojects {
    apply from: "${rootProject.projectDir}/common.gradle"
dependencies {
        implementation rootProject.ext.dependencies.mybatisGeneratorCore
    }
}

and build the project like this:
./gradlew clean :soa-illidan-mini:soa-illidan-mini-service:build -x test

and give me this error:
~/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

I am followed by internet tutorals ,what should I do to fix this problem?

A:

move your apply command to root of build.gradle like this:
apply from: "${rootProject.projectDir}/common.gradle"

just put it to top level of your project config. It works!

