Search code examples
javamavenbazel

Migrate Java EAR project from Maven to Bazel?


I have a Java Enterprise application consisting of multiple modules (several WARs and JARs and 1 Angular5 module) built and packaged into 1 thin EAR.

From a functional perspective the Maven projectstructure works fine, everything is modularized, with unittests, integration tests etc working fine.

However, due to buildspeed reasons I am looking into alternatives for Maven and Bazel keeps popping up more and more.

I have Bazel installed and have followed the simple example JAR tutorial, which works fine. I have some questions before even attempting to spec and migrate to Bazel as a POC:

  1. Am I correct in my assumption that I can gain a significant build speed improvement with Bazel over Maven for this kind of project?
  2. Are there examples to build a WAR module or EAR module with Bazel?
  3. My plan is to add the BUILD files next to the POMs as long as I am experimenting. Any downsides to that?
  4. Bazel seems very powerful since it lets me script about anything. This may also be a downside, since in Maven there are so many plugins for about anything. Any thoughts on the maintainability of the scripts or Bazel structure?
  5. I am running on Windows instead of Linux (yes.. I know). Any downsides to that in relation to Bazel? Everything seems to work fine and fast with MSYS2.

Thanks! I'd love to hear about success stories with implementing Bazel for a Java Enterprise app..


Solution

  • Disclaimer: I'm an engineer on the Bazel team.

    Am I correct in my assumption that I can gain a significant build speed improvement with Bazel over Maven for this kind of project?

    This will depend on how fast your current builds with Maven are, as well as the characteristics of your build graph.

    The company Redfin migrated from Maven to Bazel last year and experienced a 10x speedup in their CI builds (40-90 mins to 5-6 mins). They have documented this migration experience on their blog. Earlier this year, Bazel added support for remote caching, which users have reported to speed their builds up further.

    Are there examples to build a WAR module or EAR module with Bazel?

    There is the java_war packaging rule in rules_appengine. Bazel is extensible, so if the rules for a particular build step doesn't exist, it can be written as a rule extension (e.g. this list of community rules)

    My plan is to add the BUILD files next to the POMs as long as I am experimenting. Any downsides to that?

    BUILD/BUILD.bazel files are not intrusive to your project and should not affect your existing Maven builds.

    Bazel seems ver powerful since it lets me script about anything. This may also be a downside, since in Maven there are so many plugins for about anything. Any thoughts on the maintainability of the scripts or Bazel structure?

    This is a pretty subjective question, and it depends on what plugins you're dependent on.

    One migration step you might run into is the management of transitive external dependencies. There's an excellent tool called bazel-deps that helps you manage them and generates the BUILD files automatically.

    Jadep is another tool that parses your Java project and generates BUILD files for them. Check out this guide for more on Jadep.

    I am running on Windows instead of Linux (yes.. I know). Any downsides to that in relation to Bazel? Everything seems to work fine and fast with MSYS2.

    Bazel is a Windows-native binary and does not depend on the MSYS2 runtime, unless you use rules that depend on bash, like sh_library. Check out this blogpost for more: https://blog.bazel.build/2017/10/16/windows-retrospect.html