CI Using Jenkins, Maven & SVN
• Java Build Process
• Continuous Integration
• SVN - Apache Subversion
Common Project Metadata Format
Common Directory Structure
Common Build Lifecycle
Phases & Goals
• Continuous Integration – Team’s Responsibilities
Java Build Process
• "Build" is a process that covers all the steps required to create a
"deliverable" of your software.
• In the Java world, this typically includes:
Generating sources (sometimes).
Compiling test sources.
Executing tests (unit tests, integration tests, etc).
Packaging (into jar, war).
Running health checks (static analyzers like Checkstyle, Findbugs, PMD, test
Continuous Integration - Introduction
• Continuous Integration (CI) is a development practice that requires
integrate code into a shared repository several times a day. Each
check-in is then
verified by an automated build, allowing teams to detect problems
• CI Best Practices:
Maintain a single source repository
Automate the build
Make your build self-testing
Every commit should build on an integration machine
Continuous Integration – Process Overview
Continuous Integration – Why ?
• Integration of various modules at the end is hard due to following
Number of components keep increasing
Complexity of the system keeps increasing
There is no visibility of code quality & relationship between different
• CI provides following benefits:
Rapid Feedback - Detects system development problems in initial stage
Reduces risk of cost & schedule
Provides report so that one can judge the actual code quality
Continuous Integration - Tools
• Source Repository
SVN, CVS, GIT etc
• Build Tool
Maven, ANT etc
• CI Server
Jenkins, Hudson etc
SVN – Apache Subversion
• Apache Subversion is a software versioning and revision control system
• Distributed as free software under the Apache License.
• Is Open Source.
• Runs on Unix, Linux, Windows, Mac
• Client’s such as TortoiseSVN are available which provide intuitive and easy
• Developers use Subversion to maintain current and historical versions of
such as source code, web pages, and documentation.
Maven - Introduction
• Is a Java build tool.
• Is a dependency management tool
• Provides a standard development infrastructure across
• Consistent project structure & build model
• Follows standard project life cycle phases & ensures that
between projects do not need to learn new processes.
Maven - Nomenclature
• Archetype: template based on which maven
project would be created e.g.:
(An archetype which contains a sample Maven project.)
• Groupid: similar to package in java e.g:
• Artifactid: similar to project name in java e.g:
Maven – Why ?
• Project references/dependencies
Make sure jars are available during compile time
Make sure to copy jars when moving project source
Include dependencies of included jars
• Project Structure
Defines a standard project structure
• Publishing & Deploying
Allows phase-wise publishing & deployment
Maven – The Philosophy
• Maven was born of the very practical desire to make several projects at
Apache work in the same way. So that developers could freely move between
projects, knowing clearly how they all worked by understanding how one of
• Puts convention over configuration
• Do not script the build rather describe the project & configure the build
• Defines Build Patterns
Common Project Metadata Format
Common Directory Structure
Common Build lifecycles
Build Patterns – Common Project Metadata Format
• POM Project Object Model
Pom.xml Project configuration file
• Contains all metadata about the
Repositories to use
Tool links (CI, SCM, Bug Tracker etc)
Build Patterns – Common Directory Structure
• Maven is opinionated about project structure & follows
convention over configuration approach.
• Following is standard directory layout:
target: Default work directory
src: All project source files go in this directory
src/main: All sources that go into primary artifact
src/test: All sources contributing to testing project
src/main/java: All java source files
src/main/webapp: All web source files
src/main/resources: All non compiled source files
src/test/java: All java test source files
src/test/resources: All non compiled test source files
Build Patterns – Common Build Lifecycle
• Default Lifecycle phases - Invoked with ‘mvn’ command
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework e.g. junit
package - take the compiled code and package it in its distributable format, such as a JAR
integration-test - process and deploy the package if necessary into an environment where integration tests can
verify - run any checks to verify the package is valid and meets quality criteria
install - install the package into the local repository, for use as a dependency in other projects locally (Not server
deploy - copies the final package to the remote repository for sharing with other developers and projects (Not
• There are two other Maven lifecycles of note beyond the default list above:
clean: cleans up artifacts created by prior builds
site: generates site documentation for this project
Specify the phase needed to run, previous phases run automatically
Maven – Dependency Management
• Dependencies Identified by
• Declaration in pom.xml will do the following:
download the jar
add it to the classpath
• Supports Transitive dependencies
Automatically takes care of dependencies of dependencies
Maven - Repository
• Contains versioned artifacts & plugins associated with
• No need to copy libraries for each individual project
• Remote repository can be added as required
• Local repository caches artifacts to allow offline builds
• All project references go through the repository
therefore no relative paths
Maven – Phases & Goals
• Goals are executed in phases. Phases determine the order of goal’s
• The compile phase goals will always be executed before the test
phase goals which
will always be executed before the package phase goals and so on…
• When executing maven we can specify a goal or a phase, however If
you specify a
goal then it will still run all phases up to the phase for that goal. In
if you specify the jar goal it will run all phases up to the package phase
(and all goals in those phases), and then it will run the jar goal.
package jar:jar or rar:rar or war:war
Maven – Hands-on
• Install & Configure Maven
• Create a Maven Project that outputs a jar
• Add a dependency in project created above
Jenkins - Introduction
• An open source CI server
• Easy To Install and use
• Formerly known as Hudson
• Triggers a build based on some event such as notice SVN
commit or manually click build by user or build periodically.
• Generates reports & notify to team as configured
• Deploys the deliverable at given server
Jenkins - Why
• Easy GUI to Manage
• Strong Community
• Distributed Builds
• Open Source and Free
Used by leading organizations
Jenkins – Basic Steps
• Notice a change
• Checkout source code
• Execute builds/test
• Record and Publish results
• Notify Team
• Jenkins is extensible & we can add new capabilities using
• Over 600 plugins are available for Jenkins such as:
Static code analyzers
• Use Manage Plugin section for integrating plugins
Integrating Plugins – Code Quality
• Install PMD, FindBugs and checkstyle plugins from the
manage plugins option.
• Add cobertura plugin to capture the code coverage report by
• Add the plugins in the pom.xml file of the project.
• Configure the jenkins job to process the above tools.
• Install the plugins to display the violations on the jenkins
Analysis Collector Plugin, Violations, Dashboard View, Plot Plugin.
• Set goal: Cobertura:cobertura check pmd:pmd
findbug:findbug in Jenkins Job.
• Execute the build.
Continuous Integration – Team’s Responsibilities
• Check in frequently
• Don’t check in broken code
• Don’t check in untested code
• Don’t check in when the build is broken
• After checking in make sure that system builds successfully
Parece que tem um bloqueador de anúncios ativo. Ao listar o SlideShare no seu bloqueador de anúncios, está a apoiar a nossa comunidade de criadores de conteúdo.
Atualizámos a nossa política de privacidade.
Atualizámos a nossa política de privacidade de modo a estarmos em conformidade com os regulamentos de privacidade em constante mutação a nível mundial e para lhe fornecer uma visão sobre as formas limitadas de utilização dos seus dados.
Pode ler os detalhes abaixo. Ao aceitar, está a concordar com a política de privacidade atualizada.