Re-using a module/class from one Gradle project in another Gradle project

Starting to tear my hair out… I have spent a few hours getting to grips with Gradle multiprojects. But I still don’t understand what the best course of action is here. Incidentally I am using Groovy as my coding language, but explanations referencing Java would be just as good.

I have developed an Eclipse Gradle project, “ProjectA”, which in particular has a class, IndexManager , which is responsible for creating and opening and querying Lucene indices.

Now I am developing a new Eclipse Gradle project, “ProjectB”, which would like to use the IndexManager class from ProjectA.

This doesn’t really mean that I would like both projects to be part of a multiproject. I don’t want to compile the latest version of ProjectA each time I compile ProjectB - instead I would like ProjectB to be dependent on a specific version of ProjectA’s IndexManager . With the option of upgrading to a new version at some future point. I.e. much as with the sorts of dependencies you get from Maven or JCenter…

Both projects have the application plugin, so ProjectA produces an executable .jar file whose name incorporates the version. But currently this contains only the .class files, the resource files, and a file called MANIFEST.MF containing the line “Manifest-Version: 1.0”. Obviously it doesn’t contain any of the dependencies (e.g. Lucene jar files) needed by the .class files.

The application plugin also lets you produce a runnable distribution: this consists of an executable file (2 in fact, one for *nix/Cygwin, one for Windows), but also all the .jar dependencies needed to run it.

Could someone explain how I might accomplish the task of packaging up this class, IndexManager (or alternatively all the classes in ProjectA possibly), and then including it in my dependencies clause of ProjectB’s build.gradle… and then using it in a given file (Groovy or Java) of ProjectB?

Or point to some tutorial about the best course of action?