Build, Test and Deployment with Maven2

0

No comments posted yet

Comments

Slide 4

The separation of concerns (SoC) principle states that a given problem involves different kinds of concerns, which should be identified and separated to cope with complexity and to achieve the required engineering quality factors such as adaptability, maintainability, extendibility and reusability 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 repository to look in as well as the dependency's coordinates. A dependency is uniquely identified by the following identifiers: groupId, artifactId and version.

Slide 5

Slide 6

project This is the top-level element in all Maven pom.xml files. modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model. groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins. artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form <artifactId>-<version>.<extension> (for example, myapp-1.0.jar). packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects. version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide. name This element indicates the display name used for the project. This is often used in Maven's generated documentation. url This element indicates where the project's site can be found. This is often used in Maven's generated documentation. description This element provides a basic description of your project. This is often used in Maven's generated documentation.

Slide 7

process-resources : process-resources is the build lifecycle phase where the resources are copied and filtered help:describe : If you want to find out what the plugin's configuration options are, use the mvn help:describe command.

Slide 10

mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

Slide 14

Monitoring and Improving the Health of Your Source Code Accuracy – whether the code does what it is expected to do Robustness – whether the code gracefully handles exceptional conditions Extensibility – how easily the code can be changed without affecting accuracy or requiring changes to a large amount of other code Readability – how easily the code can be understood (in a team environment, this is important for both the efficiency of other team members and also to increase the overall level of code comprehension, which in turn reduces the risk that its accuracy will be affected by change)

Slide 1

Build, Test & Deployment with Apache Maven2 報告人:高明權 DATE :2009/09/18 Released V1.01 BLOG:http://tommykao.blogspot.com EMAIL : MCK6214@gmail.com

Slide 2

Maven overview

Slide 3

Main Purpose of Maven To support project management Builds Documentation Reporting Dependencies SCMs Releases Distribution

Slide 4

Maven’s Principles Convention over configuration Standard directory layout for projects One primary output per project Standard naming conventions Reuse of build logic Declarative execution Project Object Model (POM) Utilization the Build Lifecycle with Maven Phases Coherent organization of dependencies Locating dependency artifacts, POM dependency is uniquely identified by : groupId, artifactId and version.

Slide 5

Project Object Model (POM) The core of a project's configuration in Maven 2 sample : pom.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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>

Slide 6

Project Object Model (POM) project : This is the top-level element in all Maven pom.xml files. modelVersion : This element indicates what version of the object model this POM is using. groupId : This element indicates the unique identifier of the organization or group that created the project. artifactId : This element indicates the unique base name of the primary artifact being generated by this project. A typical artifact produced by Maven would have the form <artifactId>-<version>.<extension> (for example, myapp-1.0.jar). packaging : This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). version : This element indicates the version of the artifact generated by the project. name : This element indicates the display name used for the project. url : This element indicates where the project's site can be found. description : This element provides a basic description of your project.

Slide 7

Maven Phases 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. 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. 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. clean: cleans up artifacts created by prior builds

Slide 8

Build, TEST & DEPLOYMENT

Slide 9

Environments JDK & JAVA_HOME Download Maven URL : http://maven.apache.org/index.html Unzip maven C:\Program Files\Apache-maven-X.X.X folder Set maven bin path CMD EX: set PATH="c:\program files\apache-maven-2.1.x\bin";%PATH% Verify the results CMD EX: mvn –version

Slide 10

Eclipse plug-in Maven Integration for Eclipse Update Site http://m2eclipse.sonatype.org/update/ eclipse.ini -vm C:\Program Files\Java\jdk1.6.0_16\bin\javaw.exe

Slide 11

Automate Build Prepare to use maven <your-homedirectory>/.m2/settings.xml configuration for a single user Create a new project CMD EX: mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app Building the project CMD EX: mvn compile Building & testing the project CMD EX: mvn test-compile CMD EX: mvn test Prepare project release (packaging) CMD EX: mvn package Perform project release to default repository <your-homedirectory>/.m2/repository is the default location of the repository. CMD EX: mvn install

Slide 12

Archetype An archetype is defined as an original pattern or model from which all other things of the same kind are made. Goal: create a simple project based upon an archetype. CMD EX: mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-mojo

Slide 13

Maven plug-ins If you want to find out what the plugin's configuration options are, use the mvn help:describe command. CMD EX: mvn help:describe -Dfull=true -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin

Slide 14

Automate Test 1/4 To configure & generate reports

Slide 15

Automate Test 2/4

Slide 16

Automate Test 3/4

Slide 17

Automate Test 4/4

Slide 18

Automate Deployment 1/3 Automate Deployment Methods File-based deployment FTP deployment SFTP deployment SSH2 deployment External SSH deployment Deploying to the File System <distributionManagement> <repository> <id>project-repository</id> <name>Project Repository</name> <url> file://${basedir}/target/deploy </url> </repository> </distributionManagement>

Slide 19

Automate Deployment 2/3 Deploying with FTP <distributionManagement> <repository> <id>project-repository</id> <name>Project Repository</name> <url> ftp://ftpserver.yourcompany.com/deploy </url> </repository> </distributionManagement> <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ftp</artifactId> <version>1.0-alpha-6</version> </extension> </extensions> </build> Deploying with SFTP <distributionManagement> <repository> <id>project-repository</id> <name>Project Repository</name> <url> sftp://ftpserver.yourcompany.com/deploy </url> </repository> </distributionManagement>

Slide 20

Automate Deployment 3/3 Deploying with SSH2 <distributionManagement> <repository> <id>project-repository</id> <name>Project Repository</name> <url> scp://sshserver.yourcompany.com/deploy </url> </repository> </distributionManagement> Deploying with an External SSH <distributionManagement> <repository> <id>project-repository</id> <name>Project Repository</name> <url> scpexe://sshserver.yourcompany.com/deploy </url> </repository> </distributionManagement> <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh-external</artifactId> <version>1.0-alpha-6</version> </extension> </extensions> </build>

Slide 21

Build, Test & Deployment with Apache Maven2 Know-How, ExAct, Knowledge 21

Slide 22

參考資料 Apache Maven Better Builds With Maven Maven project descriptor (pom.xml) Apache Continuum Apache Archiva Continuous Integration by Martin Fowler

URL: