Automate Your Build

Some say that before you can run (write Java code in an IDE) you need to learn to walk (use the Java command-line tools). We think this is true for the complete build process of your software.

You might’ve written your first Java program in a simple text editor and used the command-line tool javac to compile your code and run it with the java command. This works as long things stay (very) simple. From our teaching experience, it also really helps beginners to get a grasp of the difference between source code and byte code.

But in any halfway realistic project, you’ll be using external libraries in the form of JARs (Java Archives), executing JUnit tests, and building JavaDoc-based documentation. If you want to do this only on the command line, you’ll end up with a lot of different and very long calls.

That’s why almost every Java developer writes Java with an IDE such as IntelliJ IDEA, Eclipse, or NetBeans. IDEs can handle all the necessary tasks we need to perform, such as executing a Java class with a main method or debugging a single JUnit test. It’s nice if you can standardize that across the team, but usually people want to work on different operating systems and/or IDEs. In that case, you can’t really rely on a single IDE anymore.

The way to go is to automate your build using a dedicated build tool or language that works in the same way on all systems and independent of a developer’s machine. Gradle[57] is such a tool. It’s the rising star for Java and the default build system for Android, but you’ll also use Apache Maven,[58] the established enterprise standard, or Apache Ant[59] often.

To automate your build, you’ll need to write a build file and put it into your project. This file uses a special syntax depending on the build tool, and in it, you describe where your source code is located, what your dependencies and external libraries are, and what else you need to do for a successful build. Then, the build tool interprets the files, downloads any external libraries, runs all tests, and if successful, builds an executable. Modern IDEs can interpret those build files as well, and they integrate with the build tools so you can run anything from within your IDE. When you’ve automated all that, you’ve taken the first steps toward a true delivery pipeline.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.170