Gradle Publish only if there is a change in module

We have gradle multi module setup for our code base. One of the module is a library which we want to publish so that others can use it by pull it from code repository.

Many time, there will be no changes in the library module, but other modules will have changes which gets build and deployed in the CI/CD pipeline.

Since we use gradle command at the top project level, it run all necessary commands in the build step.

Do we have any way to publish the module only if there is change in the repo ?
Just ignore the publish step when there is not changes in the module.

I’ve got the same setup. Lots of multi-module repositories, and I definitely don’t want/need to process them all every time an independent project changes.

I’ve largely solved the problem with a custom CICD library (Jenkins shared library in my case) which essentially:

  • gets all modules within a project
  • uses jenkins global currentBuild.changesets to determine which files have been changed
  • subsets the list of complete modules based on if they’ve changed or not
  • use that pruned list to perform the build/check/publish tasks against.

It’s not 100% targeting just the publish question that you’re looking for… but I’d ask - do you really need to build/test if you’re not publishing it?

I don’t want to publish this one sub module.
Since the sub module is part of multi-module project, the top level build command has the dependency on the publish. Hence the publish command is getting executed.