Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

16
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Continuous Integration Fundamentals Maven Joel Nation, Solutions Architect

description

Slides from the July Oracle Middleware Forum held in Canberra, Australia. Covers the next step in our continuous integration journey, namely the introduction of the build tool Maven. For more information, check out our blog at http://ofmcanberra.wordpress.com

Transcript of Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Page 1: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Continuous Integration FundamentalsMaven

Joel Nation, Solutions Architect

Page 2: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 2

What is Maven?• Apache open source project• Maven is:

– An automated build system– A project management system– A library and dependency handling system– A project description system– A site generation system

• More than just an evolution of ANT

Page 3: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 3

Primary Maven Concepts• Project Object Model (POM)

– Describes the project, it’s name/version, type, dependencies etc– Portable

• Convention over Configuration– Standard directory layout– Default behaviours for projects– Automation of build and packaging process

Page 4: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 4

POM Structure

Dependencies

Build

Plugin

Execution

Page 5: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 5

Dependencies• Maven looks for dependencies using:

– Group ID / Artifact ID / Version

• Dependencies can be scoped for– Compile / Test / Packaging / Runtime

• Maven automatically manages the download– Obtained from public and/or corporate

repositories– Stored in local repository for next use– No need to ship libraries with projecy

<dependencies> <dependency> <groupId>com.oracle.weblogic</groupId> <artifactId>weblogic-full</artifactId> <version>12.1.1</version> <scope>compile</scope> </dependency> </dependencies>

Page 6: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 6

Build Lifecycle

Validate

Integration-TestVerifyInstallDeploy

TestCompileEnsure the project is correct

Compile the source code

Test the compile code. Tests should not require the code be packaged or deployed

Package the code (eg: into a JAR)

Process and deploy the package into an environment where integration tests can be run

Copy final package to remote repository

Install the package into local repository for use as a dependency in other projects

Run checks to verify the package is valid

Package

Page 7: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 7

Typical WebLogic Phases• Pre-Integration Test

– Install WebLogic, Create Domain, Start Server, Deploy, Start App etc

• Post-Integration Test– Remove domain, Stop Server, Un-Deploy, Uninstall

• Verify, Install and Deploy are generally not used• Tests are generally run in Integration-Test as we need to deploy the app to

the server first before testing

Page 8: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 8

Plugins• Plugins perform the work

• Default set of plugins from Apache– Eg: Compile JAR, WAR etc

• Plugins can be provided by others– Automated download from repository– Can be manually installed– Oracle provides WebLogic plugins

• Can be executed as standalone goals– Eg: mvn wls:deploy

• Can be bound to a given lifecycle– Eg: mvn deploy

<plugins> <plugin> <groupId>com.oracle.weblogic</groupId> <artifactId>weblogic-maven-plugin</artifactId> <version>12.1.3-0-0</version> </plugin> </plugins>

Page 9: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 9

Executions• Map plugin functions with build

lifecycle

• Will be executed in order

• Configuration mapped to command arguments

• Access to maven variables

<execution> <id>deploy</id> <phase>pre-integration-test</phase> <goals> <goal>deploy</goal> </goals> <configuration> <user>weblogic</user> <password>welcome1</password> <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source> <verbose>true</verbose> <name>${project.build.finalName}</name> </configuration> </execution>

Page 10: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 10

Repositories• A Maven Repository holds artifacts, dependencies & plugins• Automatically looks in remote repos for missing dependencies/plugins• Default Public repo is Maven Central

– http://repo1.maven.org/maven2

• You can add more repo’s as required– Eg: Java Repo: http://download.java.net/maven2

• Can create a corporate repository

Page 11: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 11

Archetype• A project template• Allows consistent projects with best practices• Oracle provides a number of archetypes

– Basic Web-apps– J2EE Apps– SOA Apps mvn archetype:generate

-DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp -DarchetypeVersion=12.1.3-0-0 -DgroupId=com.oracle.canberra -DartifactId=my-webapp -Dversion=1.0-SNAPSHOT

Page 12: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 12

Demo 1: Maven Archetype

Page 13: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 13

Maven & Continuous Integration

Local WLS

Temp WLSCompileCreate WLSCreate DomainDeployTestUndeployRemove DomainUninstall

Version Control System

?

Page 14: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 14

Demo 2: Install WebLogic w/ Mavenhttps://github.com/Joelith/Maven-Install-WLS

Page 15: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 15

• Introduced with 10.3.4– Maven Mojo + WebLogic Deployer + WebLogic

Client– Supports: list-apps, deploy/undeploy, start,

stop and update

• 12.1.2– Embedded maven repo– Maven Synchronization plugin– New archetypes/projects

• 12.1.1– Can install WebLogic zip distribution where

WebLogic has not been installed– WebLogic Domain Creation– Execute WLST scripts

• 12.1.3– wlst-client goal to run online WLST without

local WebLogic

WebLogic Support

Page 16: Continuous Integration Fundamentals: Maven - OFM Canberra July 2014

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 16

More Information• Oracle Maven Integration Documentation

– http://docs.oracle.com/middleware/1213/wls/WLPRG/maven.htm#CHDCDGCG

• RedStack Maven Posts– http://redstack.wordpress.com/tag/maven/

• Our blog– http://ofmcanberra.wordpress.com