|
Comments
|
Today's Top SOA Links
Feature Java Feature: Build Management Allows Developers to Develop
Enable more flexible and manageable development environments
By: Matt Gabor
Dec. 29, 2005 05:15 PM
Whether writing code for a small, single-platform environment or contributing to a sophisticated cross-platform, multi-language application, one truth remains consistent: a disorganized or poorly implemented build management strategy will adversely affect a developer's workflow.
In small- and medium-sized environments, using a properly implemented in-house build system can mitigate many of the risks and challenges associated with builds. In addition, with a few simple steps, the burdensome task of developing and maintaining build scripts can be significantly reduced, allowing developers to focus on writing code rather than debugging builds. As development efforts grow in size and complexity, however, there comes a point where significant benefits can be realized by moving to an automated system. Whether using a manually scripted or automated build solution, every enterprise should strive for build consistency, portability, and repeatability.
Build Management Evolution Java development required a new, platform-independent build tool, leading to the creation of Apache Software Foundation's Java-based Ant, so-named by developer James Duncan Davidson because, "…it is a little thing that can build big things." Ant eliminates Make's platform-dependent problems and is extended not with shell-based commands but Java classes. Configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by a Java class that implements a particular task interface. Ant is powerful, but the XML configuration scripts can create limitations. XML does not handle conditional logic effectively and therefore it's difficult to use Ant to write "intelligent" build scripts that support robust batch processing. In addition, many development projects include Java and non-Java components that require both Ant and Make, as neither handles both languages. Scripting for the two is very different. Make scripts are the input to Make programs and dictate how to build each software component. A Make file tells the Make program which binaries are to be created from which source modules. Make rules are then "fired" based on out-of-date conditions between source and object. In contrast, Ant/XML scripting uses serial batch processing. Rules for creating Java binaries such as .jar, .war, and .ear are handled statically for each step or "task" in the XML script. Listing 1 shows the differences between Make and Ant scripts for a similar type of build task. For either approach, the programmer must understand not only how the application is constructed, but also the specific syntax requirements of the build scripting language they are using. In addition, Make and Ant/XML scripts are not re-usable because static application information is coded into the script.
Make and Ant/XML Challenges Although most Ant build systems do not appear to be as complex as many Make-based build systems, it is only a matter of time. Because Ant is a relatively young technology, Ant-based build systems have not been subjected to the years of additions and changes that can corrupt and obscure what originally appears to be an elegant build scripting solution. Over the years, as Ant scripts suffer from being passed through different developers' hands, as new technology emerges that effects the way Ant scripts are coded or used, and as applications grow more complex, Ant will encounter many of the problems associated with a Make-based system. Scripted build processes also introduce other challenges that devour developers' time. In fact, build scripting can be the most time-consuming and resource-intensive component faced by development teams. Problems scale with an environment's size and complexity. The key is to implement best practices for manual scripting starting with an in-house build system, while monitoring factors that would signal the need to move to an automated, non-scripting approach.
Solving Typical Scripting Problems The first step is to shift from a developer-centric view of builds to a team-centric view, and from the notion of scripting "my build solution" to scripting "our build solution." Build inconsistency is the toughest problem. If developers use their own build scripts in the language or tool of choice, it can be difficult to know whether problems result from bad code or a bad build. Build administrators must standardize on a single scripting approach that best suits the language being used. The first step to reducing build inconsistency between individual developer's build scripts is to develop build script templates that can be used as a basis for all build scripts. All builds require the same basic information: source code, compiler, and final target. Individual developers can populate the build script templates with their own build specifics, i.e., the source code location, compiler location, and a final target description. Build script templates should be well commented and clearly organized to ease the process of populating the template with build-specific information. A major contributing factor to build inconsistency is a lack of compiler and third-party library standardization. In a disparate build environment, developers frequently build against different versions of compilers and third-party libraries. This makes it difficult to re-create builds and diagnose problems. Instead, to promote standardization, all compilers should be centralized on a network drive accessible by all developers, on a clean and "locked down" machine. The build script templates should specifically reference the standard compiler versions on the mapped network drives, ensuring that all builds occur against consistent compiler versions. All third-party libraries should similarly be consolidated on a shared network drive so that the latest, approved versions are used. Another commonly faced problem is a lack of build portability. Builds often work only on an individual developer's machine, which by default becomes the "production" build machine. The philosophy is, "build it where it builds and get it out the door." Obviously, this approach to builds can cause severe problems when trying to track down bugs that are discovered once an application has been released to production. To solve this problem, development teams should standardize their directory structure. All developers should work on code in the same directory structure. If a versioning or CM tool is used, pull the directory structure from it; if not, enforce strong directory conventions for all developers. Portability problems can also be mitigated by using global variables in the build script templates that identify the root location for all source code, compilers, and common libraries. By setting environment variables, such as SRC_HOME, COMPILER_HOME and COMMON_HOME, the same build scripts should work on all machines. Using global variables in the build script templates also reduces the amount of template editing that is required by developers. The Make code (see Listing 2) is a generic example that demonstrates the use of a standardized compiler to ensure build consistency and the use of global variables to guarantee portability. Note the global variables defined at the top of the script. Each developer can edit the values to suit his or her own workstation. In addition, the cc compiler is pulled in through a shared network drive referenced in the COMPILERDIR variable. Reader Feedback: Page 1 of 1
Your Feedback
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||