I worked on a project that uses a framework. To add a new sub class I had to change the visibilities of the super class that was part of the framework. I was able to compile the the framework on my own without the need to create a local repository, create a new artifact and new version by:
- using a composite build
- substitute the dependency
- convert dependent project to a gradle project
A composite build is a build that consists of multiple builds. It’s like a project with submodules but on the build level.
One use case for dependency substitution is to use a locally developed version of a module in place of one that is downloaded from an external repository. This could be useful for testing a local, patched version of a dependency.
The module to be replaced can be declared with or without a version specified. By default, Gradle will configure each included build in order to determine the dependencies it can provide. The algorithm for doing this is very simple: Gradle will inspect the group and name for the projects in the included build, and substitute project dependencies for any external dependency matching
In the build.gradle you already have a dependency, because you have worked with the framework already.
Now we want to replace this dependency with full control over the source code. Add the following to the settings.gradle to declare a composite build and substitute a dependency with that build.
rootProject.name = 'app'
substitute module('org.sample:theframework') with project(':')
Convert Dependency to Gradle Project
In my case the framework is using maven as build system. This won’t work so I have to convert the maven project to a gradle project first.
Checkout the framework from source into the directory specified in inlucdeBuild. In my case that is ./modules/theframework.
git clone <url> modules/theframework
Now we have the gradle project. Review the generated modules/theframework/build.gradle (especially the sourceCompatibility and targetCompatibility). The project should compile fine on it’s own.
We have everything set up now. Make your changes to the dependency you have full control about now. Work on your own project and figure out changes that are required to the framework.