While one way is with a multi-module gradle build, this is not helpful when the individual microservices are split across multiple repos, each with their own repos and build.gradle
.
In this case, there are additional options, each with their own caveats.
mavenLocal
You can publish your common.jar
to your maven local with something like this.
This works well if you only have a single development machine, otherwise, each developer will have to publish to local as well. Also, for distribution, you would have to bundle common.jar
into the final jar, which you are likely doing already since it is included locally.
This approach would at least prevent you from having to copy/paste.
Run a maven server
Or, of course, you could run a maven on some machine all your devices have access to. Nexus works well. There are others.
This requires a dedicated "server" of some kind to run this. Might not work in all envs, but might be something worth investing in.
Gradle Task
And, of course, as a 'low-tech' solution, if you have a common directory structure and always work out of a workspace where you have all your other repos, you can have a task in the common
's Gradle build that after building the jar simply copies the build artifact to the other repos based on known paths and a list of repos to update.
While potentially brittle, you could even perform git commands on those folders and prepare commits to add the changed file. YMMV on this, though, as it has plenty of its own pitfalls.
This requires all repos to be cloned, in the same relative paths, but has the advantage of simply removing the manual effort.
Scripting
And, of course, there's no reason you have to use Gradle to do the above. If can't use a multi-module build, and you can't use any of the other tasks, consider writing a script (bash, pwsh, python, etc), and at take advantage of some automation.
Yes, it has the pitfalls of the above, but it is simpler than doing a lot of manual tasks over and over, all of which have the potential of being skipped, forgotten, etc.