Search code examples
javalernamonorepo

Lerna-like tools / handling monorepos in Java


I come from a web-development background and have frequently worked on projects that use Lerna for handling multiple packages from the same repository in JavaScript. As it stands now, I need to recreate some of those projects in Java, and need to know how to do it without using Lerna, and using Gradle as our build tool.

My questions are about how to handle a large repository with multiple packages in Java:

Edit: Rewording the question to fit in the guidelines. Keeping the old questions below in strike through so old answers make more sense.

  1. Do I need to use a separate tool to help manage packages in Java like Lerna does for JavaScript, or can a build tool such as Maven or Gradle handle that on its own.
  2. If two teams are using different build tools, is it more prone to cause problems for their various contributions?
  3. Is maintaining multiple Java packages within one repository viable in the first place?


  1. Are there any packages or plugins that already do this in Java? (I was unable to find any.)
  2. Will solutions likely cause problems between teams using different build tools for their various contributions? (ex: Maven and Gradle)
  3. Is maintaining multiple Java packages within one repository viable in the first place?
  4. Is there anything I am fundamentally failing to understand while asking this? Am I headed in the wrong direction for finding a solution?

Solution

  • At this point in time, the de-facto standard for Java project management seems to be a combination of gradle and maven (via a gradle plugin).

    The combination of these two eliminates the need for tooling such as Lerna, as they allow local dependencies to be configured out of the box.

    After setting up a multi-project build, you can add sibling projects as dependencies like so:

    dependencies {
        compile project(':sibling')
    }
    

    If you use an IDE such as Intellij IDEA for instance which supports gradle, it will create the initial directory structure for you when you create a gradle project, and configure new modules that you create via its UI. It might be a good idea to play with this for a little bit in order to get a grasp of how it's all wired up.