Commit 2f45f1f1 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Maven presentation is now more general, about 'build automation'

parent f0e0169f
Pipeline #14785 passed with stages
in 4 minutes and 10 seconds
= Apache Maven
:revealjs_center: false
:revealjs_display: flex
:revealjs_transition: none
:revealjs_slideNumber: c/t
:revealjs_theme: stereopticon
:revealjs_width: 1920
:revealjs_height: 1080
:revealjs_history: true
:revealjs_margin: 0
:source-highlighter: highlightjs
:imagesdir: images
:includedir: includes
:sectids!:
= Build Automation
== Agenda
* *Introduction*
* Software Artifacts
* Build Tools
* Maven
* GitLab CI
* Conclusion
== Definition
[quote,Wikipedia]
____
Build automation is the process of automating the creation of a software build and the associated processes including: compiling computer source code into binary code, packaging binary code, and running automated tests.
____
image::build-big-picture.png[align=center]
== Build Automation Goals
[.columns]
--
[.col-8]
* Eliminate redundant tasks
* Reduce dependencies on key personnel
* Log the history of builds and releases in order to investigate issue
* Improve product quality
* Accelerate the build process
* Reduce build issues.
[.col-4]
image::save-time.png[align=center]
--
== Motivation
[.block]
Build is just compilation...
image::build-compilation.png[align=center]
== Motivation (cont.)
[.block]
and packaging ...
image::build-packaging.png[align=center]
== Motivation (cont.)
[.block]
and testing ...
image::build-testing.png[align=center]
== Motivation (cont.)
[.block]
and integrating ...
image::build-integration.png[align=center]
== Motivation (cont.)
[.block]
and evaluating the tests ...
image::build-evaluation.png[align=center]
== Motivation (cont.)
[.block]
and generating some code ...
image::build-generation.png[align=center]
== Motivation (cont.)
[.block]
and generating the documentation ...
image::build-documentation.png[align=center]
== Motivation (cont.)
[.block]
and deploying ...
image::build-deployment.png[align=center]
== Motivation (cont.)
[.block]
and also:
. Processing resources
. Keeping a history of builds
. Source code analysis
. Managing release versions
. and several other little things!
== Agenda
* Introduction
* *Software Artifacts*
* Build Tools
* Maven
* GitLab CI
* Conclusion
== Understanding Software Artifacts
[quote]
____
In software construction, the term *software artifact* denotes a software that has been documented and stored in a repository so it can be retrieved upon demand.
____
image::software-artifact.png[align=center]
== Artifact Dependencies
[.columns]
--
[.col-4]
****
.Software Artifact
image::cd-software-artifact.png[align=center]
****
[.col-8]
****
.Software Artifact Example
image::od-software-artifact.png[align=center]
****
--
== Dependency Scope
image::dependency-scope.png[align=center,height=800px]
== Dependency Scope (Cont.)
.Different Scopes:
Runtime:: The dependency is needed during compilation, testing and execution
Testing:: The dependency is only needed during testing
Compile:: The dependency is only needed during compilation
Provided:: The dependency is needed during compilation and testing, but should not be embedded in the package: it will be provided by the execution environment
== Dependency Versions
image::dependency-version.png[align=center,height=800px]
== Version Ranges
[%header,cols=2*]
|===
|Range
|Meaning
|(,1.0]
|x <= 1.0
|1.0
|It generally means 1.0 or a later version, if 1.0 is not available. Various Maven plug-ins may interpret this differently, so it is safer to use one of the other, more specific options.
|[1.0]
|Exactly 1.0
|[1.2,1.3]
|1.2 <= x <= 1.3
|===
== Version Ranges (Cont.)
[%header,cols=2*]
|===
|Range
|Meaning
|[1.0,2.0)
|1.0 <= x < 2.0
|[1.5,)
|x >= 1.5
|(,1.0],[1.2,)
|x <= 1.0 or x >= 1.2. Multiple sets are separated by a comma.
|(,1.1),(1.1,)
|This excludes 1.1 if it is known not to work in combination with the library.
|===
== Agenda
* Introduction
* Software Artifacts
* *Build Tools*
* Maven
* GitLab CI
* Conclusion
== Apache Maven
[.columns]
--
[.col-4]
[link=http://maven.apache.org]
image::maven-logo.png[align=center]
[.col-8]
* Java Build and Dependency resolution tool from Apache Foundation
* Introduced several standards: project layout, artifact repository organization, build lifecycle, etc.
* Most used Java build tool
--
== Gradle
[.columns]
--
[.col-4]
[link=https://gradle.org/]
image::gradle-logo.png[align=center]
[.col-8]
* Open-source build tool, based on Maven standards.
* Advantages over Maven:
** Flexibility
** Performance
** Better user experience (DSL vs. XML)
--
== GitLab CI
[.columns]
--
[.col-4]
[link=https://about.gitlab.com/product/continuous-integration/]
image::gitlab-logo.png[align=center]
[.col-8]
* Open-source, Continuous Integration and Continuous Delivery tool combined with GitLab.
* Simple fast, scalable, and multi-language.
* Supports Docker
--
== SonarQube
[.columns]
--
[.col-4]
[link=https://www.sonarqube.org]
image::sonarqube-logo.png[align=center]
[.col-8]
* Open-source platform used to measure and analyze the source code quality
* Can analyze and manage code of more than 20 programming languages, including Java, c/c++, PL/SQL, and Cobol
* Enables Continuous Code Quality Management
--
[.small]
https://sonarcloud.io
== Agenda
* Introduction
* Dependency Resolution
* Software Artifacts
* Build Tools
* *Maven*
* GitLab CI
* Conclusion
== Foreword
«Maven was born of the practical desire to make several projects at the Apache Software Foundation(ASF) work in the same, predictable way.
[.columns]
--
[.col-4]
[link=http://maven.apache.org]
image::maven-logo.png[align=center]
Before, every project at the ASF had a different approach to compilation, distribution, and web site generation. Ex. Build process for Tomcat was different from build process used by Struts. Turbine developers used a different approach to site generation than the developers of Jakarta, Commons, etc. (…)»
[.col-8]
[cite]
____
Maven was born of the practical desire to make several projects at the Apache Software Foundation(ASF) work in the same, predictable way.
____
--
'''
[%notitle]
== Apache Maven
« (…) This lack of common approach to building software meant that every new project tended to copy and paste another project’s build system.
[quote]
____
Before, every project at the ASF had a different approach to compilation, distribution, and web site generation.
Ex. Build process for Tomcat was different from build process used by Struts. Turbine developers used a different approach to site generation than the developers of Jakarta, Commons, etc.
____
The barrier to entry for a project with a difficult build system was extremely high. Difficult to attract developer because it could take an hour to configure everything in just the right way.»
[%notitle]
== Apache Maven
http://maven.apache.org
[quote]
____
This lack of common approach to building software meant that every new project tended to copy and paste another project’s build system.
'''
The barrier to entry for a project with a difficult build system was extremely high. Difficult to attract developer because it could take an hour to configure everything in just the right way.
____
== Maven is
== Apache Maven
* A project management framework.
* A build tool.
* A set of standards.
* An artifact repository.
* An standard build life cycle.
'''
.Maven is a:
* Project management framework.
* Build tool.
* Set of standards.
* Artifact repository.
* Standard build life cycle.
== Principles
== Main Principles
«Convention over configuration»
[quote]
____
Convention over configuration
____
«Reuse of build logic»
____
Reuse of build logic
____
'''
== Conventions
* Standard directory layout: sources, resources, config files, generated output, documentation, web site, etc.
* A single Maven project produces a single output.
* Standard naming conventions.
'''
== Features
* A comprehensive software project model (POM) and tools that interact with this declarative model.
* Allows developers to declare goals and dependencies and rely on default structure and plugin capabilities.
'''
== Benefits
* Coherence: Maven allows organizations to standardize on a set of best practices.
* Reusability (reusing the best practices).
'''
== Benefits
* Agility: lowers the barrier to reuse not only of build logic but of components. It is easier to create a component and integrate it to a multi-project build. Easier for developers to jump between projects without the a steep learning curve.
* Agility: lowers the barrier to reuse not only of build logic but of components.
** It is easier to create a component and integrate it to a multi-project build.
** Easier for developers to jump between projects without the a steep learning curve.
* Maintainability: stop building the build and focus on the application.
'''
== The Project Object Model
......@@ -81,40 +396,34 @@ http://maven.apache.org
</dependency>
</dependencies>
</project>
----
* This pom will allow you to compile, test and generate basic documentation.
'''
== Build lifecycle
* A series of phases where each phase can perform one or more actions, or goals, related to that phase.
* For instance, the compile phase invokes a certain set of goals to compile set of classes.
'''
== Build lifecycle
* If you tell Maven to compile, the validate, initialize, generate-sources, process-sources, generate-resources, and compile phases will execute.
'''
== Build lifecycle
* Standard build life cycle consists of many phases and these can be thought of as extension points.
* When you need to add some functionality to the build lifecycle you do so with the plugin.
'''
== Build lifecycle
* Maven Plugins provide reusable build logic that can be slotted into the standard build life cycle.
* Any time you need to to customize the way your projects builds you either employ the use of an existing plugin or create custom plugin for the task at hand.
'''
== Default build lifecycle
image:resources/png/build-lifecycle.png[]
image::build-lifecycle.png[align=center]
'''
== Default build lifecycle (simplified)
......@@ -122,37 +431,38 @@ image:resources/png/build-lifecycle.png[]
. *compile* - compile the source code of the project
. *test* - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
. *package* - take the compiled code and package it in its distributable format, such as a JAR.
'''
== Build lifecycle (cont.)
. *integration-test* - process and deploy the package if necessary into an environment where integration tests can be run
. *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
. *deploy* - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
'''
== Dependencies
* A dependency is a reference to a specific artifact that resides in a repository.
* In order for Maven to attempt to satisfy a dependency, Maven needs to know what the repository to look in as well as the dependency’s coordinates.
* A dependency is uniquely identified by the following identifiers: groupId, artifactId and version.
'''
== Dependencies are declaratives
* In the POM you are not telling Maven where the dependencies physically, you are simply telling Maven what a specific project expects.
'''
== Dependencies
* When a dependency is declared, Maven tries to satisfy that dependency by looking in all of the remote repositories that are available, within the context of your project, for artifacts that match the dependency request.
* If matching artifact is located, it transports it from remote repository to your local for general use.
'''
== Dependency Declaration
[source,xml]
----
<project>
:
(...)
<dependencies>
<dependency>
<groupId>junit</groupId>
......@@ -161,32 +471,34 @@ image:resources/png/build-lifecycle.png[]
<scope>test</scope>
</dependency>
</dependencies>
:
(...)
</project>
----
'''
== Repositories
* Types of repositories:
[.columns]
--
[.col-4]
image::repository.png[align=center]
[.col-8]
.Types of repositories:
. Local: `~/.m2/repository`
** you must have a local repository in order for Maven to work.
. Remote
--
image:resources/jpg/repository.jpg[]
'''
=== General pattern for the repository layout
== General pattern for the repository layout
image:resources/jpg/repository-pattern.jpg[]
image::repository-pattern.png[align=center]
If the groupId is a fully qualified domain name such as `z.y.x` then you would end up with a directory structure like the following:
image:resources/jpg/directory-pattern.jpg[]
image::directory-pattern.png[align=center]
'''
== Locating Dependency Artifacts
......@@ -195,23 +507,27 @@ image:resources/jpg/directory-pattern.jpg[]
. By default, Maven will fetch an artifact from the central Maven repository at https://repo.maven.apache.org/
. If your project’s POM contains more than one remote repository, Maven will attempt to download an artifact from each repository in the order defined in your POM.
. Once dependency is satisfied, the artifact is downloaded and installed in your local repository.
'''
[.impact]
== Getting Started with Maven
'''
== Preparing to use Maven:
. Download Maven from http://maven.apache.org and unzip it to your desired installation directory. Ex. C:\maven in Windows, or /usr/local/maven in Linux.
. Add System variable M2_HOME as well as $M2_HOME/bin directory to your system path.
. Add System variable `M2_HOME` as well as $M2_HOME/bin directory to your system path.
. Type the following in a terminal or command prompt:
[source,sh]
----
mvn --version
----
'''
[%notitle]
== Preparing to use Maven:
. If you are behind a firewall, create a `&lt;your-home-directory&gt;/.m2/setting.xml` with the following content:
[source,xml]
----
......@@ -227,7 +543,9 @@ mvn --version
</settings>
----
'''
[%notitle]
== Preparing to use Maven:
. If there is an active Internal Maven proxy running. create a <your-home-directory>/.m2/setting.xml with the following content:
[source,xml]
----
......@@ -243,7 +561,6 @@ mvn --version
</settings>
----
—-
== Creating your First Maven Project
......@@ -256,7 +573,9 @@ mvn archetype:generate -DgroupId=fr.unantes.datatypes
-DinteractiveMode=false
----
'''
[%notitle]
== Creating your First Maven Project
* New directory `units` has been created for the new project, and this directory contains your `pom.xml` which looks like the following file:
[source,xml]
----
......@@ -280,12 +599,12 @@ mvn archetype:generate -DgroupId=fr.unantes.datatypes
</project>
----
'''
* Directory structure of your project after archetype generation:
[%notitle]
== Creating your First Maven Project
image:resources/png/units.png[]
.Directory structure of your project after archetype generation
image::units.png[align=center,height=800px]
'''
== Maven Basic Commands
......@@ -296,7 +615,6 @@ image:resources/png/units.png[]
* Make a JAR file or the package: `mvn package`
* take a look at the target directory and you will see the generated JAR file.
* Install the artifact(JAR file) you’ve generated into your local repository so that it can be used by other projects. `&lt;your-home-directory&gt;/.m2/repository`is the default location: `mvn install`
'''
== Test Execution
......@@ -309,7 +627,6 @@ image:resources/png/units.png[]
* `**/Abstract*Test.java`
* `**/Abstract*TestCase.java`
—-
== Website/Reports Generation
......@@ -328,7 +645,241 @@ image:resources/png/units.png[]
* Maven is a set of standards, a repository, a framework and is a software.
* Maven is more than just downloading another JAR and a set of scripts, it is the adoption of processes that allow you to take your software to the next level.
'''
== Agenda
* Introduction
* Dependency Resolution
* Software Artifacts
* Build Tools
* Maven