Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put user-project specific Gradle properties?

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.

like image 834
Cimlman Avatar asked Jan 04 '19 13:01

Cimlman


People also ask

How do you set a project property?

To set project propertiesFrom the Tools menu, choose <projectname> Properties. Use the General tab in the <projectname> Properties dialog box to specify the following: Name of your project. Description of your project.

What is Gradle user home directory?

The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.


1 Answers

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

like image 67
ToYonos Avatar answered Oct 12 '22 13:10

ToYonos