简体   繁体   中英

What's a simple way to share gradle settings between gradle builds

I've got an app which now includes a gradle build for a wearable app.

So both build.gradle files have something like

    versionCode 1230
    versionName "1.23.0"

Is there a simple properties file I can place the two values in and then reference them in both builds so I don't forget to update both and help ensure they both stay the same?

A gradle.properties file in the project root will have its properties injected as what amount to global variables available to your build.gradle files.

So, for example, I might have a gradle.properties file in the project root that has:

PUBLISH_GROUP_ID=com.commonsware.cwac
PUBLISH_ARTIFACT_ID=anddown
PUBLISH_VERSION=0.2.1
LOCAL_REPO=file:///this/would/be/a/real/path/to/a/local/maven/repository

Then, in modulename/build.gradle (where modulename is app or anddown or whatever your module is), I can refer to those values:

apply plugin: 'maven'

uploadArchives {
    repositories.mavenDeployer {
        pom.groupId = PUBLISH_GROUP_ID
        pom.artifactId = PUBLISH_ARTIFACT_ID
        pom.version = PUBLISH_VERSION

        repository(url: LOCAL_REPO)
    }
}

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