build : Java Glossary
©1996-2017 2014-05-30 Roedy Green of Canadian Mind Products
If you have a large project, you often want a way to avoid recompiling everything.
You want something to track what really needs to be recompiled. It is actually a
little more subtle than examining the timestamps to see which files have changed
since the last compile. If unchanged files use static final constants that may have
changed, they too need to be recompiled. Various tools make various brave attempts at
deciding what needs to be recompiled. However, it is wise to recompile the universe
from time to time in case something slipped through the cracks, especially the final
build and test before shipping. Any tool for doing this in generically called a
A build tool tackles one or more of the following problems:
- loading Javac.exe only once rather than once per soure file or once per package.
Javac.exe is incredibly fast if you don’t keep reloading it.
- Figuring out which *.java files need to be recompiled.
- Figuring out which *.class files should go in which jars.
- Collecting class files into jar files.
- Digitally signing jar files.
- Figuring out which jar files have to be rebuilt because some of its contained class files have changed.
- Running unit tests.
- Preparing files for distribution.
- Managing a source code repository
Stages of Life vis a vis Build Tools
- If you are a newbie, you build your jars manually at the command line with
- Then you progress to using BAT (Batch) file scripts.
- You might then use JavaCompiler interface to load javac.exe once and compile everything.
- Then you start using ANT which is not all that different
from running BAT scripts.
- Then you add GenJar to manage your dependencies
(figuring out which class files belong in which jars). However, it will fail if
your projects get big.
- Then you add Ivy to manage your dependencies.
- Ant’s XML (extensible Markup Language) is pretty clumsy and does not encourage encapsulation, so you
augment ANT (A Neat Tool) with Java programs that generate ANT scripts.
- Generating ANT scripts is indirect and gives you little power to control what
happens when the script runs, so you might eventually dump XML and use Gradle’s much more programmerly syntax. It more for a
corporation than a hobbyist. Learning such a complicated and powerful tool is quite
- Then you get a job with a large corporation. They use Maven which is XML based and very rigidly structured. You have to
use it whether you like it or not. You may also learn it simply because so many
open source projects now are distributed as Maven repositories.
- Then you go for continuous integration tools like
Jenkins that use servers to continuously build and test
software as teams check in modules.