Where to put user-project specific Gradle properties?
Asked Answered
R

1

12

Gradle properties are stored to the file named gradle.properties. It can be located in the project root directory or in ~/.gradle/

According to this discussion on gradle.org, the property file in the project root should contain project specific properties and should be under source control (Git in my case). User specific properties should be in ~/.gradle/gradle.properties so that they are not committed under SCM.

But where should I put properties that are specific to a particular user on a particular project, let's say credentials to central Git repository?

I am using jgitflow-gradle-plugin that requires properties gitUsername and gitPassword. These properties should not be committed definitely. Therefore, they cannot be placed in gradle.properties in project root directory. On the other hand, they should not be shared by different projects as I can use different Git central repository with different credentials.

Is there a way to use multiple gradle.properties files in a single project? One of them would be committed and another one would be git-ignored.

Rodrick answered 4/1, 2019 at 13:32 Comment(0)
T
4

You should try the Gradle Properties Plugin. It enhances the way Gradle loads properties from various properties files.

1# Set it up :

plugins {
  id 'net.saliman.properties' version '1.4.6'
}

Or the old way (Gradle <= 2.0)

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'net.saliman:gradle-properties-plugin:1.4.6'
    }
}

apply plugin: 'net.saliman.properties'

2# Create a gradle-local.properties file in the project directory and gitignore it. Add your credentials into it.

3# Keep the original gradle.properties under version control and keep inside it properties you want to be shared through git

Tootsy answered 4/1, 2019 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.