How to reference other classesdir in Gradle multi-project build

151 Views Asked by At

I am building an API using spring boot. I'm using gradle and a multi-project build set up where I have a services-lib project and an api project that depends on the services-lib.

Running the api:bootRun tasks in the api project works perfectly fine, but now I'm trying to add the ability to trigger an spring-boot-devtools automatic restart, which requires the bootRun task to have the service-lib classdir in it's classpath(not the jar that is added by the multi-project dependency).

Adding this to my api's build.gradle does trigger the automatic restart when I run the api:build task (where "C:/foo/bar" is the absolute path to my multi-project root directory).

bootRun {
    classpath += files('C:/foo/bar/services-lib/build/classes/java/main')
}

My question is, instead of having to hard code that path, can I set it using something like project(':services-lib')?

1

There are 1 best solutions below

0
On

Well I did figure this out thanks to Kidus' suggestion.

bootRun {
    bootRun.systemProperty 'spring.profiles.active', 'dev'
    classpath += files('../services-lib/build/classes/java/main')
}

It still means if I change anything about the build output in the services-lib project I have to change it hear but at least now when others check out the project now it will work for them.