Search code examples
javamavengradle

Why Maven or Gradle come into picture?


I know core Java and want to learn Maven and Gradle. However, I would like to understand why Maven or Gradle is necessary. Is there a way to understand the problems we would encounter without using these build tools? I am also interested in learning how to build projects without using any build tools. Technologies emerge to solve specific issues, and I want to understand the challenges Java developers were facing that led to the development of Maven and Gradle.


Solution

  • Why Maven or Gradle come into picture?

    Because building non-trivial applications by running javac from the command line leads to mistakes, non-reproducible builds and so on.

    The history is roughly as follows

    • Running javac by hand is tedious and unreliable.
    • Shell scripts that run javac etc are cumbersome, and a maintenance burden.
    • Make came next1, but Make didn't understand Java, so you ended up recompiling a lot of Java classes unnecessarily.
    • Then came Ant, but that didn't understand Java library dependencies. (That lead to the practice of embedding copies of JARs for dependencies into the repositories of the projects that use them. And consequent difficulties.)
    • Then came Maven which provided a system to describe and manage dependencies. Also it introduced a standard way of structuring the code and non-code files in a project.
    • Then came Gradle which has a more flexible (non-linear) model of how tasks are performed. And performance.
    • Then came Bazel which is more focused on reproducibility of builds.

    The differences between Maven, Gradle and Bazel are more pronounced for large projects.


    1 - "Next" in terms of its use for Java builds. The Make tool itself predates Java by many years.