There is a simple java project core
, which has utility classes and configurations that are directly imported to the microservices(Spring Boot). In this case, api
and admin
.
Here is a build.bradle
setting to show the project structure.
project(':core') {
dependencies {
}
}
project(':api') {
apply plugin: 'war'
build.dependsOn ':core:build'
dependencies {
compile project(':core')
}
}
project(':admin') {
apply plugin: 'war'
build.dependsOn ':core:build'
dependencies {
compile project(':core')
}
}
I think microservices supposed to be independent of one another, so this core
project might have some potential problem in the future. For example, we have a datasource properties in the core
project. What if a new microservice requires another datasource? While we can override core
properties using another properties file and profile, I think this only makes settings unnecessary complicated. Maybe even more if common classes need to be changed.
Is having a core project that shares common classes and properties to microservices a good practice?
I think it's totally fine. Think about this core module as 3rth party dependency which you plugged into your microservices. To deal with potential problems when the core module will have breaking changes you have to make api/admin module depending on a specific version of the core module so instead of depending on com.myapp.core:RELEASE
use com.myapp.core:1.2.4
and slightly migrate your upstream modules to the fresh version of the core. In this case, you won't have any issues and your microservices will be still independent with each other.