Search code examples
javaspringspring-bootgradlespring-properties

Gradle String Boot multi-projects, expand application.properties


I'm using gradle to manage a multi-modules spring boot project.

->Root

---> module-1
--------->src/main/java
--------->src/test/java/application.properties

---> module-2
--------->src/main/java
--------->src/test/java/application.properties

---> SHARED-FOLDER
---------> data.json

In my test application.properties of module-1 I want to reference SHARED-FOLDER/data.json file, something like :

application.properties

my.json.data.file=SHARED-FOLDER/data.json

But it's not working. I've tried :

my.json.data.file=${user.dir}/SHARED-FOLDER/data.json

but user.dir references module-1not root

How can I reference root/SHARED-FOLDER/data.json in an application.properties inside another module?


Solution

  • I've managed to add the shared folder to my classpath and then reference it like :

    my.json.data.file=classpath:data.json

    In my gradle sub-modules I've added :

    subprojects {
        apply plugin: 'java'
    
        sourceSets {
            main {
                resources {
                    srcDirs += [
                            "$rootDir/SHARED-FOLDER"
                    ]
                }
            }
        }
    }