Contenu connexe Similaire à Continuous Integration Fundamentals: Maven - OFM Canberra July 2014 (20) Continuous Integration Fundamentals: Maven - OFM Canberra July 20141. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Continuous Integration
Fundamentals
Maven
Joel Nation, Solutions Architect
2. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
2
3. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
3
4. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
POM Structure
4
Dependencies
Build
Plugin
Execution
5. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
5
<dependencies>
<dependency>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-full</artifactId>
<version>12.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
6. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Build Lifecycle
6
Validate
Integration-TestVerifyInstallDeploy
TestCompile
Ensure 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
7. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
7
8. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
8
<plugins>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>12.1.3-0-0</version>
</plugin>
</plugins>
9. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Executions
• Map plugin functions with build
lifecycle
• Will be executed in order
• Configuration mapped to command
arguments
• Access to maven variables
9
<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>
10. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
10
11. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Archetype
• A project template
• Allows consistent projects with best practices
• Oracle provides a number of archetypes
– Basic Web-apps
– J2EE Apps
– SOA Apps
11
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
12. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Demo 1: Maven Archetype
12
13. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Maven & Continuous Integration
13
Local WLS
Temp WLS
Compile
Create WLS
Create Domain
Deploy
Test
Undeploy
Remove Domain
Uninstall
Version Control
System
?
14. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Demo 2: Install WebLogic w/ Maven
https://github.com/Joelith/Maven-Install-WLS
14
15. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
• 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
15
• 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
16. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
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
16