I have a project with a main module and several sub-modules managed using git submodules. I want to use continuous integration and deployment (CI/CD) to build an image of one of the sub-modules. However, I’m unsure how to access the properties and plugins from the main module’s build.gradle file for the sub-projects, even though I have the main module’s Maven coordinates.
After simplifying my project structure, it looks like this:
parent
│ .gitignore
│ .gitmodules
│ build.gradle
│ gradlew
│ gradlew.bat
│ HELP.md
│ settings.gradle
└─server
│ .gitignore
│ build.gradle
│ Dockerfile
│ gradlew
│ gradlew.bat
│ HELP.md
│
├─gradle
│ └─wrapper
│ gradle-wrapper.jar
│ gradle-wrapper.properties
│
└─src
In the build.gradle of my parent, the dependencies and plugins of the child project are defined as follows:
subprojects {
apply plugin: 'java'
...
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
...
}
}
Using the gitmodules method, the parent and server are stored in different git repositories:
.gitmodules
[submodule "server"]
path = server
url = <https://gitee.com/xxxxx>
branch = master
Now the problem is that there is no problem running locally because they are in the same directory and can find each other through relative paths, but when you want to use CI/CD, relative paths no longer work. For example, if there is this property in the build.gradle of the server project:
sourceCompatibility = '17'
This is a very simple property used to set the compilation version. If locally, when compiling in server through the parent’s subproject, there will be no errors. But in general, when submitted to your own repository, an error will occur because the plugin ‘java’ cannot be found since the parent cannot be obtained (because both parent and server have their own repositories). This leads to inconsistent results between local builds and CI/CD environments. If you are using Maven, server can obtain this pom file through the parent’s coordinates and then inherit it, so there is no impact. But in Gradle, what should be done?