Download presentation
Presentation is loading. Please wait.
Published byMarlene Stafford Modified over 9 years ago
1
Intermediate Maven Michael Youngstrom
2
Notes This is a training NOT a presentation Please ask questions No making fun of my microphone Prerequisites – Introduction to Maven – Basic Java and XML skillz
3
Outline Review Introduction to Maven Plugins Properties Profiles
4
Review Maven is a build tool Maven project Structure Maven has a build lifecycle A maven artifact is identified with GAV Maven dependencies are glorious!
5
Maven Plugins Plugins extend Maven Plugins are identified with GAV Two ways to execute a plugin – Hook into build lifecycle – Invoke standalone
6
Hooking into build lifecycle Allows plugin to execute as part of maven build Three items to configure a plugin: – Phase – Goal – Configuration
7
Plugin Example... org.apache.maven.plugins maven-enforcer-plugin 1.0... execute validate enforce...
8
Plugin Documentation Use Plugin reference documentation! Full NameDefault PhaseConfiguration
9
Plugin Configuration Configuration parameters go in the configuration element....... false... true
10
PluginManagement PluginManagement configures a plugin without executing it – Version – Configuration – Executions To execute use: – Regular Plugin entry – Plugin standalone command
11
Plugin Management Example org.apache.maven.plugins maven-enforcer-plugin 1.0... true org.apache.maven.plugins maven-enforcer-plugin
12
Plugin Inheritance This is a rather complex topic Plugin inherits PluginManagement configuration Plugins and PluginManagement can inherit config from parent Beyond that you can figure it out on your own
13
How to Manage POM Complexity Effective POM – Flattens POM configuration – Dependency and DependencyMangement is resolved – Plugin and PluginManagement is resolved – Executions are Resolved – Properties are Resolved (more on this later) – Profiles are Resolved (more on this later) To use: – Select the “Effective POM” tab in pom editor in Eclipse – Invoke mvn help:effective-pom on command line
14
Invoking Plugins Standalone Plugins can also be invoked adhoc from command line – GroupId:ArtifactId:Version:Goal – Will use Plugin Management configuration – Configuration can be provided by system properties Can be shortened Must be configured in pom plugin or in settings.xml mvn org.apache.maven.plugins:maven-enforcer-plugin:1.0:enforce mvn enforcer:enforce
15
Plugin Documentation Helps Plugin reference documentation rocks! Short NameFull Name
16
Setting Configuration Standalone Expression: the property key to this parameter Expression Key mvn enforcer:enforce –Denforcer.fail=false
17
Lab 1: Maven Plugins https://tech.lds.org/wiki/Intermediate_Maven#Lab _1_Maven_Plugins
18
Maven Properties Properties are the glue that tie configuration together Properties can come from several places: – element in pom – System Properties – Project Object Model Properties can be used as a value just about anywhere – Plugin Configuration – Resource Filtering Properties can only be simple primitive values
19
Maven Property Example... true org.apache.maven.plugins maven-enforcer-plugin 1.0 ${skipEnforcer}
20
POM Properties Element Properties can be nested... true ${skipTests}
21
System Properties Supplied to the command line using “-D” – mvn install –DskipEnforcer=true Supplied in the IDE using parameters dialog System Properties override POM properties
22
Project Object Model Properties Properties can be derived from POM structure POM elements = property keys – Expression: ${project.version} Element: – Expression: ${project.artifactId} Element: – Expression: ${project.build.sourceDirectory Special properties: – ${basedir}: Directory of current project – ${maven.build.timestamp} : Start of build.
23
Inherited Properties Properties can be inherited and overridden Current property value depends upon context... true ${skipTests}... false
24
Resource Filtering Project resources can use properties Resources filtered in process-resources phase Filtering can be turned off on a per resource directory basis Some Text File in /src/main/resources: ${someProperty} Some Text File in /src/main/resources: SomeValue... SomeValue
25
Properties and Plugin Expression Properties can also override plugin expression defaults Expression Key
26
Skip Enforcer Example #1... org.apache.maven.plugins maven-enforcer-plugin 1.0 true
27
Skip Enforcer Example #2 true org.apache.maven.plugins maven-enforcer-plugin 1.0
28
Skip Enforcer Example #3 org.apache.maven.plugins maven-enforcer-plugin 1.0 mvn clean install –Denforcer.skip=true
29
Lab 2: Maven Properties https://tech.lds.org/wiki/Intermediate_Maven#Lab _2_Maven_Properties
30
Maven Profile Allows activating a set of alternative configurations Works for: – Properties – Dependencies – Plugins – etc. Inherits and extends non-profile configuration
31
Profile Example... enforcer false
32
Profile Activation Can be Activated: – By Default – Explicitly by name – Based on a Property – Based on operation system – Existence of a file
33
Activation from Command Line Activates a profile explicitly Multiple profile ids are comma delimited mvn clean install –P enforcer
34
Activation in IDE Build Can be set in build command configuration
35
Activation in IDE Development Can be set in project’s Maven config Usually used to change development mode
36
Lab 3: Maven Profiles https://tech.lds.org/wiki/Intermediate_Maven#Lab _3_Maven_Profiles
37
Summary Plugins extend Maven’s capabilities Properties are the glue in Maven configuration Profiles enable alternate configurations Next training understanding Stack Starter’s Maven Configuration
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.