Maven. INF5750/ Lecture 2 (Part II)

Similar documents
What is Maven? Apache Maven is a software project management and comprehension tool (build, test, packaging, reporting, site, deploy).

Simplified Build Management with Maven

Topics covered. Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session. Maven 2

Apache Maven. Created by anova r&d bvba

Pour aller plus loin : Programmation outillée

Struts 2 Maven Archetypes

MAVEN INTERVIEW QUESTIONS

MAVEN MOCK TEST MAVEN MOCK TEST IV

MAVEN MOCK TEST MAVEN MOCK TEST I

Maven POM project modelversion groupid artifactid packaging version name

I Got My Mojo Workin'

Content. Development Tools 2(57)

Maven Introduction to Concepts: POM, Dependencies, Plugins, Phases

Package Management and Build Tools

Produced by. Agile Software Development. Eamonn de Leastar

Apache Maven MarsJUG. Arnaud Héritier exo platform Software Factory Manager

Software Engineering - Development Infrastructure 2. Kristjan Talvar Nortal

DevOps and Maven. Eamonn de Leastar Dr. Siobhán Drohan Produced by:

Setting up a Maven Project

Maven in the wild. An introduction to Maven

TIBCO StreamBase 10.2 Building and Running Applications in Studio, Studio Projects and Project Structure. November 2017

Maven 2 & Continuum. by Trygve Laugstøl

Repository Management and Sonatype Nexus. Repository Management and Sonatype Nexus

maven Build System Making Projects Make Sense

Set up Maven plugins in Eclipse. Creating a new project

Component based Development. Table of Contents. Notes. Notes. Notes. Web Application Development. Zsolt Tóth

Example ear-testing can be browsed at

Session 24. Spring Framework Introduction. Reading & Reference. dev.to/lechatthecat/how-to-use-spring-boot-java-web-framework-withintellij-idea-202p

4. Check the site specified in previous step to work with, expand Maven osgi-bundles, and select slf4j.api,

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

Red Hat JBoss Fuse 6.1

Administering Apache Geronimo With Custom Server Assemblies and Maven. David Jencks

Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

The Actual Real World at EclipseCon/ALM

MAVEN SUCKS NO(W) REALLY

B O NU S C H A P T E R

Contents. Enterprise Systems Maven and Log4j. Maven. What is maven?

Packaging, automation, Continuous Integration

Sonatype CLM Enforcement Points - Nexus. Sonatype CLM Enforcement Points - Nexus

Maven 2 The powerful buildsystem. a presentation for EL4J developers by Martin Zeltner (MZE) November 2007

STQA Mini Project No. 1

Construction: version control and system building

EPL451: Data Mining on the Web Lab 6

... Maven.... The Apache Maven Project

MANUAL DO ALUNO DE ENGENHARIA DE SOFTWARE

Studienarbeit Nr Web-based Application Integration: Advanced Business Process Monitoring in WSO2 Carbon. Jakob Krein

Cheat Sheet: Wildfly Swarm

sites</distribsiteroot>

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

... Fisheye Crucible Bamboo

Getting started with Geomajas. Geomajas Developers and Geosparc

JPA Tools Guide (v5.0)

Executable business processes in BPMN 2.0 IN ACTION. Tijs Rademakers. FOREWORDS BY Tom Baeyens. AND Joram Barrez SAMPLE CHAPTER MANNING

Red Hat JBoss Fuse 6.2.1

Distributing JavaFX Applications with Java WebStart and Artifactory

MAVEN MOCK TEST MAVEN MOCK TEST III

Fat / Uber jars - Using the Shade Plugin

Maven Plugin Guide OpenL Tablets BRMS Release 5.16

Please see the docs for latest release in 1.99.* Some of the information below might be outdated

gradle : Building Android Apps Mobel Meetup

juddi Developer Guide

Red Hat JBoss Fuse 6.2

APEX Developer Guide. Sven van der Meer, Liam Fallon, John Keeney. Version SNAPSHOT, T11:44:57Z

Red Hat JBoss Fuse 6.3

Software Building (Sestavování aplikací)

Groovy. Extending Java with scripting capabilities. Last updated: 10 July 2017

TOP REASONS WHY YOU SHOULD SWITCH TO MAVEN 3

JDO Tools Guide (v5.1)

The Workshop. Slides (you have a copy in the zip) Practical labs Ask questions

OOP with Java. Homework 05: Maven. Thomas Weise 汤卫思.

JVM Survival Guide. Hadi Hariri

Junit. Presentation & Tools (Eclipse, Maven, Mockito, Spring)

Red Hat JBoss Fuse 6.2.1

Sonatype CLM - IDE User Guide. Sonatype CLM - IDE User Guide

Unable To The Artifact From Any Repository Maven-clean-plugin

Introduction to project industrialization using Maven YaJUG 06/10/2009. Copyright Pierre-Antoine Grégoire License Creative Commons 2.

District Health Information Software 2 (DHIS 2)

Checking Out and Building Felix with NetBeans

Step 2. Creating and running a project(core)

vrealize Code Stream Plug-In SDK Development Guide

mvn package -Dmaven.test.skip=false //builds DSpace and runs tests

<put document name here> 1/13

Hello Gradle. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

Sonatype CLM - CI User Guide. Sonatype CLM - CI User Guide

Apache Maven. Péter Jeszenszky Faculty of Informatics, University of Debrecen Last modified: March 8, 2018

Tuscany: Applying OSGi modularity after the fact

JAVA V Tools in JDK Java, winter semester ,2017 1

Advanced Dependency Management with Gradle. Benjamin Muschko, Gradle Inc.

Oracle Corporation

... SysML version SNAPSHOT Developer Guide.... Eclipse

Exceptions and Libraries

Repository Management with Nexus

FROM NOTHING TO COMPLETE ENVIRONMENT WITH MAVEN, OOMPH & DOCKER. Max Bureck, 21. June 2017

An Integrated Approach to Managing Windchill Customizations. Todd Baltes Lead PLM Technical Architect SRAM

Class Dependency Analyzer CDA Developer Guide

Maven 2.1 Artifact Resolution Specification

Red Hat JBoss BPM Suite 6.0

SOA-14: Continuous Integration in SOA Projects Andreas Gies

Red Hat JBoss Fuse 6.3

Workflow. Summary. Prerequisites. Getting your module ready. Create a new module

Transcription:

Maven INF5750/9750 - Lecture 2 (Part II)

Problem! Large software projects usually contain tens or even hundreds of projects/modules Very different teams may work on different modules Will become messy if the projects don t adhere to some common principles Will be time-consuming to build all projects manually

The solution Use a project management tool (like Maven) Maven helps you with various aspects: 1. Build process 2. Project structure 3. Dependency management 4. Access to information and documentation

Build process The Project Object Model (POM) an XML file is the heart of a Maven 2 project Contains project information and configuration details used to build the project Project dependencies Commands (goals) that can be executed Plugins Metadata The POM extends the Super POM Only 4 lines are required Default values for repositories, project structure, plugins

POM file - simple example <project> <modelversion>4.0.0</modelversion> <groupid>no.uio.inf5750</groupid> <artifactid>assignment-2</artifactid> <version>1.0-snapshot</version> <packaging>jar</packaging> <name>assignment 2</name> <dependencies> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.1.1</version> <scope>compile</scope> </dependency> </dependencies> Object model version Group / organization id Id of the project itself Version of the project Packaging type Display name of the project Dependencies

POM - Project inheritance Project A (Parent) <project> <modelversion>4.0.0</modelversion> <groupid>no.uio.inf5750</groupid> <artifactid>projecta</artifactid> <version>1</version> <packaging>war</packaging> </project> Project B Project C Project D Project B inherits war packaging <project> <parent> <groupid>no.uio.inf5750</groupid> <artifactid>projecta</artifactid> <version>1</version> </parent> <modelversion>4.0.0</modelversion> <groupid>no.uio.inf5750</groupid> <artifactid>projectb</artifactid> <version>1</version> </project>

POM - Project aggregation Project B Project A (Parent) Project C Project D A command against Project A will be run against Project B as well <project> <modelversion>4.0.0</modelversion> <groupid>no.uio.inf5750</groupid> <artifactid>projecta</artifactid> <version>1</version> <packaging>pom</packaging> <modules> <module>projectb</module> <module>projectc</module> <module>projectd</module> </modules> </project> <project> <modelversion>4.0.0</modelversion> <groupid>no.uio.inf5750</groupid> <artifactid>projectb</artifactid> <version>1</version> </project>

Build lifecycle and phases The build lifecycle is the process of building and distributing an artifact A phase is a step in the build lifecycle Most important default phases: Validate Compile Test Package Install Deploy Some common phases not default: Clean Site For each step, all previous steps are executed

Standard directory layout Advantages: A developer familiar with Maven will quickly get familiar with a new project No time wasted on re-inventing directory structures and conventions src/main/java src/main/resources src/main/filters src/main/config src/main/webapp src/test/java src/test/resources src/test/filters src/site Java source files goes here Other resources your application needs Resource filters (properties files) Configuration files Web application directory for a WAR project Test sources like unit tests (not deployed) Test resources (not deployed) Test resource filter files (not deployed) Files used to generate the Maven project website

Dependency management Dependency: a third-party or project-local software library (JAR or WAR file) Dependency management is a challenge in multi-module projects Keep in mind that this is different from Spring s dependency management (dependency injection), but similar. Maven handles larger modules. Spring connects Java objects.

Dependency management Project A Dep. A Dep. B Dep. C Project B Dep. A Dep. B Dep. C The poor approach: Replicate all dependencies for every project (put in /lib folder within the project) Dependencies are replicated and use more storage Checking out a project will be slow Difficult to keep track of versions

Dependency management Dep. A Dep. B Repository Dep. C The preferred solution: Use a repository Repository: A shared location for dependencies which all projects can access Only one copy exists Stored outside the project Dependencies are defined in the POM Project A Project B <dependencies> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</groupid> <version>1.1.1</version> </dependency> </dependencies>

Repositories Remote repo Local repo (Internet) (Local computer) Remote repository: Provides software artifacts (dependencies) for download E.g. repo1.maven.org houses Maven s central repository Local repository: Copy on local computer which is a cache of the remote downloads May contain project-local build artifacts as well Located in USER_HOME/. m2/repository Same structure as remote repos Project A Project B

Repositories Downloading from a remote repository Central repo is default Can be overridden Internal repositories Often used in corporate environments to avoid connection to the internet Improves security, speed, and bandwidth usage Suitable for publishing private artifacts <repositories> <repository> <id>my-repo-</id> <url>http://my-server/repo</url> </repository> </repositories> Remote repo (Internet) Internal repo (In-house) Local repo (Local computer) Project B Project A (Local computer)

Transitive dependencies Maven reads the POM files of your dependencies and automatically includes their required libraries No limit on the number of levels Dependency mediation nearest definition Commons-logging, JUnit, and Log4J 1.3 will be installed in local repo automatically Log4J 1.3 Log4J 1.2 Project A Commons-logging JUnit

Dependency scope Affects the classpath used for various build tasks Can be defined for all dependencies, compile default 5 dependency scopes available: Compile: Available in all classpaths (default) Provided: The JDK or the servlet container provides it Runtime: Only required for execution, not for compilation Test: Only required for testing, not for normal use (not deployed) System: You provide it locally, not looked up in a repo <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.4</version> <scope>compile</scope> </dependency>

Dependency management Mechanism for centralizing dependency information Favourable for projects that inherits a common parent Useful for controlling versions of transitive dependencies Parent POM <dependencymanagement> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</groupid> <version>4.0</version> <scope>test</scope> <type>jar</type> </dependency> </dependencies> </dependencymanagement> Child POMs... <dependency> <groupid>junit</groupid> <artifactid>junit</groupid> </dependency>... Child POM dependency inherits information from parent POM Transitive occurences of JUnit guaranteed to be of version 4.0

Project information Powerful feature in Maven: Create a project site automatically Info retrieved from the POM, source code Provides information regarding Dependencies Issue tracking Licensing Development team Provides various reports Test coverage Internationalisation JavaDocs Potential code problems

Useful commands $ mvn package Compile and create JARs/WARs $ mvn install Package + copy to local repo $ mvn clean Delete target directory $ mvn test Run unit tests $ mvn eclipse:eclipse Create Eclipse project files $ mvn idea:idea Create IDEA project files $ mvn jetty:run-war Run a WAR file in Jetty $ mvn site Generates project site $ mvn install -DskipTests Skip tests (saves time)

Summary We ve learned that Maven facilitates: Uniform building of projects through the POM Consistent project structure Management of dependencies through repositories to avoid replication and ease re-use and versioning Standardized project information

Resources Better builds with Maven Free PDF book online http://www.maestrodev.com/better-buildmaven Maven homepage Documentation and guides http://maven.apache.org