Gradle: multiple application.properties for multi-project build with profile support

Viewed 686

Basically, I want to have something like the following structure:

├── ...
├── core-module
│   ├── build.gradle
│   └── src
│       ├── main
│       |   └── java
│       |   └── resources
│       |       └── application.properties
│       |       ├── application-dev.properties
│       |       ├── application-test.properties 
│       |       └── application-prod.properties
│       └── test
│           └── java
├── dogs-module
│   ├── build.gradle
│   └── src
│       ├── main
│       |   └── java
│       |   └── resources
│       |       └── application.properties
│       |       ├── application-dev.properties
│       |       ├── application-test.properties 
│       |       └── application-prod.properties
│       └── test
│           └── java
├── cats-module
│   ├── build.gradle
│   └── src
│       ├── main
│       |   └── java
│       |   └── resources
│       |       └── application.properties
│       |       ├── application-dev.properties
│       |       ├── application-test.properties 
│       |       └── application-prod.properties
│       └── test
│           └── java
├── birds-module
│   ├── build.gradle
│   └── src
│       ├── main
│       |   └── java
│       |   └── resources
│       |       └── application.properties
│       |       ├── application-dev.properties
│       |       ├── application-test.properties 
│       |       └── application-prod.properties
│       └── test
│           └── java
├── src?
└── ...
  • dogs, cats and birds modules have the core (or base/common) module as a dependency. For Gradle, it's compile project(':core').
  • dogs, cats and birds modules are not related in any way. The only common feature is the core project.

I am planning the default root src directory to be empty but I could use application.properties, application-{profile}.properties here for some initialization too, if possible.

├── ...
└── src
    └── main
        ├── java
        └── resources
            └── application.properties
            ├── application-dev.properties
            ├── application-test.properties 
            └── application-prod.properties

How can I load properties this way for an environment profile so that properties in the next file could override properties from the previous one?

For instance, core ← dogs:

  • root-application.properties
  • root-application-prod.properties
  • core-application.properties
  • core-application-prod.properties
  • dogs-application.properties
  • dogs-application-prod.properties
0 Answers
Related