I have a multi module Spring Boot Application with following folder structure
MyProject/
|-pom.xml
|-Module1/
|--pom.xml
|--src/
|---main/
|----java/
|-----module-info.java
|-----com.project.module1/
|----resources/
|-----module1-application.properties
|-----module1-application-dev.properties
|-----module1-application-prod.properties
|---test/
|----java/
|-----com.project.module1/
|----resources/
|-----module1-application-test.properties
|-Module2/
|--pom.xml
|--src/
|---main/
|----java/
|-----module-info.java
|-----com.project.module2/
|----resources/
|-----module2-application.properties
|-----module2-application-dev.properties
|-----module2-application-prod.properties
|---test/
|----java/
|-----com.project.module2/
|----resources/
|-----module2-application-test.properties
|-Main/
|--pom.xml
|--src/
|---main/
|----java/
|-----module-info.java
|-----com.project.main/
|------Main.java
|----resources/
|-----main-application.properties
|-----main-application-dev.properties
|-----main-application-prod.properties
|---test/
|----java/
|-----com.project.main/
|----resources/
|-----main-application-test.properties
And my main class looks like
@SpringBootApplication(scanBasePackages = {"com.project"})
@EntityScan(basePackages = {
"com.project.module1.models",
"com.project.module2.models"
})
@EnableJpaRepositories(basePackages = {
"com.project.module1.repositories",
"com.project.module2.repositories"
})
public class Main {
public static void main(String[] args){
//Setting up multiple spring profiles
new SpringApplicationBuilder(Main.class)
.properties(
"spring.config.name" +
":main-application" +
",module1-application" +
",module2-application"
)
.build().run(args);
}
}
Application runs fine and reads the properties file as expected. Issue arises when I have to run commands like flyway migration or tests which do not access Main class and hence fail to load migration related properties.
Is there any way I can define base properties class in individual module's pom.xml?
I have come across some solutions that requires defining different properties for different profiles, but that is too much of configuration, I am currently looking for a solution as simple as defining spring.config.name
with base properties name in individual pom.xml