A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
flexible
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
flexible
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
flexible
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
flexible
configurable
A build manager is a tool for scripting the automated steps required to produce a software artifact.
What Should a Build Manager Do?
A good build manager should be
easy to use
easy to set up for a given project
efficient in performing the build
incremental
flexible
configurable
Let’s talk about how development projects are typically organized into files, directories, etc.
A project consists of one or more more sub-projects.
What Constitutes a Sub-project?
A sub-project is generally defined as the code and data that yields a single deliverable.
Examples of deliverables include
.jar
or.a
, .lib
, .so
, or .dll
Example: The AlgAE project has sub-projects
sub-project deliverable algae-client-server algae-4.1.jar
algae-cppserver libalgaecpp.a
algae-referenceManual referenceManual.pdf
demos/FordToppBST FordToppBST.zip
demos/ReferenceManualJava algae-jrefman.jar
Why divide a project into multiple sub-projects rather than into multiple smaller independent projects?
Why divide a project into multiple sub-projects rather than into multiple smaller independent projects?
The entire project is stored in a single location/repository.
Why divide a project into multiple sub-projects rather than into multiple smaller independent projects?
The entire project is stored in a single location/repository.
The entire project can be built with a single command.
Why divide a project into multiple sub-projects rather than into multiple smaller independent projects?
The entire project is stored in a single location/repository.
The entire project can be built with a single command.
Why divide a project into multiple sub-projects rather than into multiple smaller independent projects?
The entire project is stored in a single location/repository.
The entire project can be built with a single command.
Typically contains
Top-level directory contains:
build.xml
: builds the sub-projects in the correct order.git
, .gitignore
, ivysettings.xml
(version control and configuration management)All but the last are sub-projects.
C/C++ projects might add directories that will (after the project is built) contain the various sub-projects’ deliverables:
Contains:
The Apache Foundation hosts many open source projects, which organize their projects & sub-projects like this:
src/ # anything supplied/edited by the programmers
target/ # initially empty, holds products of the compilation/build
The src/
directory is split into separate directories for the "real’ code and for the test code.
src/
| main/ # things that contribute directly to the deliverable
| test/ # things used for testing but not delivered
target/
“Deliverables” are usually an archive of some kind.
If the project is supposed to produce a Java application or a Java library, the deliverable is usually packaged in a Jar.
Server-side web applications are delivered in a War or an Ear.
Source code is sometimes packaged in a Jar, but more often in a Zip. (Usually, though, when we talk about deliverables in this section, we’ree referring to “binary” deliverables.)
Android apps are packaged in an APK.
The division of the source files into separate main/
and test/
makes it easier to eventually construct those deliverable archives because we won’t treat entire directories worth of stuff uniformly, rather than having to select desired materials on a file-by-file basis.
src/main/
is further subdivided:
src/
| main/
| | java/ # Java source code, compiled into target/classes
| | resources/ # data files that will be included in the deliverable archive
| | data/ # data files required during build but not part of deliverable
| test/
target/
| classes/ # data and compiled code that are packed into the .jar deliverable
| project.jar # the deliverable
(These directories can be omitted if they are empty.)
Java libraries and applications can read data from files within their own distribution archive with only slightly more difficulty than reading from an ordinary file. To do so, the Java code is written to search the Java CLASSPATH
, the same path used to hunt for the compiled Java code.
They cannot, however, write to those data files. The data access is read-only.
The src/test/
directory is split in an analogous fashion:
src/
| main/
| | java/
| | resources/
| | data/
| test/
| | java/ # Java source code, compiled into target/test-classes
| | resources/ # data files, available during testing via CLASSPATH
| | data/ # test data
target/
| classes/
| test-classes/ # data and compiled code for unit testing
| project.jar
Test resources are intended to be accessible during testing via the code already written for accessing main (deliverable) resources. One way to support this is to copy the src/test/resources
contents into target/test-classes
, so that the same CLASSPATH
-based mechanisms to locate the compiled test code will also find the test resources.
A similar directory structure is employed for Android projects. The Gradle build manager, which we will cover later in this section, has made the Android structure its default for Java projects, making it a popular organization for non-Apache projects.
The most obvious difference is that the products of the build are stored in build
instead of target
.
src/ # anything supplied/edited by the programmers
build/ # initially empty, holds products of the compilation/build
The src/
directory is laid out identically to the Apache organization:
src/
| main/
| | java/ # Java source code. After compilation, is part of the deliverable.
| | resources/ # Data files that will be included in the deliverable, accessible via CLASSPATH
| | data/ # Data files needed for the build, but not part of the deliverable.
| test/
| | java/ # Java source code for testing, will not be part of the deliverable
| | resources/ # data files, available during testing via CLASSPATH
| | data/ # test data
build/
Example: see this structure in the Code Annotation project
Much more variation exists. One possibility is:
include/ # header files
|
src/ # compilation units (.c and .cpp files)
|
bin/ # executables and .o files produced by compiling src/
|
lib/ # libraries produced by combining object files
.o
files are placed in a separate obj/
directory.bin/
or lib/
directory.Increasingly common is this approach, inspired by the Apache/Android Java styles:
src/
| main/
| | cpp/ # C++ source code. .cpp files and local headers
| | headers/ # Header (.h) files that need to be visible to main code and
| | # to tests.
| | public/ # For library projects, the header files that will be exported
| | # as part of the delivered library.
| test/
| | cpp/ # Unit test code
| | data/ # test data
build/
| exe/ # Executables
| | main/ # - from main/cpp
| | test/ # - from test/cpp
| lib/ # libraries constructed from object code
| | main/ # - from obl/main
| obj/ # Compiled object code
| | main/ # - from main/cpp
| | test/ # - from test/cpp
| tmp/ # Work area for general temporary files
Boxes are files.
Arrows denote dependencies. “A depends on B” means that if B is missing or changed, then A must be (re)generated.
Labels on arrows indicate the program used to generate the file at the base of the arrow.
Analysis of such a graph facilitates
efficiency - easy to tell what needs to be rebuilt after a change
incrementality - can determine required build step for any file, not just the “final” one
make is the canonical example of a build manager of this type.
make is a command/program that enacts builds according to a dependency graph expressed in a makefile.
make devised by Dr. Stuart Feldman of Bel Labs in 1977
It has long been a standard component of *nix systems
At its heart, a makefile is a collection of rules.
A rule describes how to build a single file of the project.
Each rule indicates
Rules may appear in any order
The Components of a Rule
target: dependencies
commands
where
target is the target file,
dependencies is a space-separated list of files on which the target is dependent
commands is a set of zero or more commands, one per line, each preceded by a Tab character.
Rule Examples
codeAnnotation.jar: code2HTML.class CppJavaScanner.class
jar tvf codeAnnotation.jar code2HTML.class CppJavaScanner.class
CppJavaScanner.class: CppJavaScanner.java
javac CppJavaScanner.java
code2HTML.class: code2HTML.java CppJavaScanner.java
javac code2HTML.java
CppJavaScanner.java: code2html.flex
java -cp JFlex.jar JFlex.Main code2html.flex
Pros & Cons
Ellipses are tasks (activities). Each task can involve multiple steps.
Arrows denote success dependencies. “A depends on B” means that A will be run after B and only if task B finished successfully.
This approach facilitates
ease of setup: usually less detailed than a full file-based dependency graph
incrementality - can request any intermediate step
ant is based on this approach.
ant devised by James Davidson of Sun, contributed to Apache project (along with what would eventually become TomCat), released in 2000
Quickly became a standard tool for Java projects
ant
itself is implemented in JavaAt its heart, a build file is a collection of targets.
A target is an XML element and, as attributes, has a name and, optionally,
The target can contain multiple tasks, which contain the actual “commands” to get things done.
Example of Targets
<project name="JavaBuild" default="deploy"> ➀
<description>
Example of a simple project build
</description>
<target name="compile" description="Compile src/.../*.java into bin/"> ➁
<mkdir dir="bin" /> ➂
<javac srcdir="src" destdir="bin"
debug="true" includeantruntime="false"/>
<echo>compiled </echo>
</target>
<target name="unittest" depends="compile" unless="test.skip"> ➃
<mkdir dir="test-reports" />
<junit printsummary="on" haltonfailure="true"
fork="true" forkmode="perTest">
<formatter type="plain" />
<batchtest todir="test-reports">
<fileset dir="bin">
<include name="**/Test*.class" />
<exclude name="**/Test*$*.class" />
</fileset>
</batchtest>
</junit>
</target>
<target name="deploy" depends="unittest" description="Create project's Jar file">
<jar destfile="myProject.jar">
<fileset dir="bin"/>
</jar>
</target>
</project>
➀ The project has a name and default target
➁ A basic target. It is named “compile” and has a description (which may be picked up by some IDEs)
➂ This target has 3 tasks. It creates a directory, compiles Java source code, and prints a message when completed.
➃ This target illustrates both a dependency and a condition.
Another Apache project, Maven came well after Ant had come to dominate the Java open source landscape.
Initially seen as a competitor or replacement for Ant
Maven addresses both
Grew out of an observation that many supposedly cooperative, related Apache projects had inconsistent and incompatible ant build structures.
Stated goals are
Making the build process easy
Providing a uniform build system
Providing quality project information
Providing guidelines for best practices development
Allowing transparent migration to new features
The build file for maven
is also in XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.odu.cs</groupId> ➀
<artifactId>codeAnnotation</artifactId> ➁
<packaging>jar</packaging>
<version>1.0</version>
<name>codeAnnotation</name>
<url>https://www.cs.odu.edu/~zeil/cs795SD/s13/Directory/topics.html</url>
<description>
This is a tool used to parse code listings and to
generate syntax-highlighted C++/Java listings in both
HTML and LaTeX.
</description>
<!-- site generation:
mvn test
mvn surefire-report:report
mvn site
-->
<repositories>
</repositories>
<dependencies> ➂
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.jflex</groupId>
<artifactId>jflex</artifactId>
<version>1.4.3</version>
</dependency>
</dependencies>
<build>
<plugins> ➃
<plugin>
<groupId>de.jflex</groupId>
<artifactId>maven-jflex-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
jflex
plugin at ➃ant
and ask it to take care of this”pom.xml files have a dependencies
section. e.g.,
<dependencies>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependencies>
This indicates that our project requires the junit package.
[4.10,]
to get versions 4.10 or greaterMaven does a transitive search over the dependencies for a project
Maven then downloads the required libraries automatically
~/.m2
)By default, Maven searches the ibiblio repository, which can be human-searched here.
Try searching for junit
<dependencies>
section to request this version.How does Maven know whether junit itself depends on other libraries?
Near the top of the junit 4.10 page, click to “View” the POM file:
Near the bottom, you will see
<dependencies>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependencies>
This is the same kind of info that we put into our own pom.xml file
ant
got jealous…
ant
aquired a plugin, Ivy
, that allowed it to handle 3rd party libraries in an almost identical fashion.Combine
For this we, will look to gradle
.