1 / 37

Michael Youngstrom

Intermediate Maven. Michael Youngstrom. 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. Outline. Review Introduction to Maven Plugins Properties Profiles. Review.

marc
Download Presentation

Michael Youngstrom

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 <project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> <configuration> ... </configuration> <executions> <execution> <id>execute</id> <phase>validate</phase> <goals><goal>enforce</goal></goals> <configuration> ... </configuration> </execution> </executions> </plugin> </plugins> </build> </project>

  8. Plugin Documentation • Use Plugin reference documentation! Full Name Default Phase Configuration

  9. Plugin Configuration • Configuration parameters go in the configuration element. <project> ... <plugin> ... <configuration> <fail>false</fail> </configuration> <executions> <execution> ... <configuration> <failFast>true</failFast> </configuration> </execution> </executions> </plugin> </project>

  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 <project> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> <configuration> ... <ignoreCache>true</ignoreCache> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> </plugin> </plugins> </build> </project>

  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 mvnhelp: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 pomplugin or in settings.xml mvn org.apache.maven.plugins:maven-enforcer-plugin:1.0:enforce mvnenforcer:enforce

  15. Plugin Documentation Helps • Plugin reference documentation rocks! Short Name Full Name

  16. Setting Configuration Standalone • Expression: the property key to this parameter Expression Key mvnenforcer: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: • <properties/> 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 <project> ... <properties> <skipEnforcer>true</skipEnforcer> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> <configuration> <skip>${skipEnforcer}</skip> </configuration> </plugin> </plugins> </build> </project>

  20. POM Properties Element • Properties can be nested <project> ... <properties> <skipTests>true</skipTests> <skipEnforcer>${skipTests}</skipEnforcer> </properties> </project>

  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: <project><version/></project> • Expression: ${project.artifactId} • Element: <project><artifactId/></project> • Expression: ${project.build.sourceDirectory • <project><build><sourceDirectory/></build></project> • 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 <project> ... <properties> <skipTests>true</skipTests> <skipEnforcer>${skipTests}</skipEnforcer> </properties> </project> <project> <parent> ... </parent> <properties> <skipTests>false</skipTests> </properties> </project>

  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 <project> ... <properties> <someProperty>SomeValue</someProperty> </properties> </project> Some Text File in /src/main/resources: ${someProperty} Some Text File in /src/main/resources: SomeValue

  25. Properties and Plugin Expression • Properties can also override plugin expression defaults Expression Key

  26. Skip Enforcer Example #1 <project> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> <configuration> <skip>true</skip> </configuration> </plugin> </project>

  27. Skip Enforcer Example #2 <project> <properties> <enforcer.skip>true</enforcer.skip> </properties> <build> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> </plugin> </build> </project>

  28. Skip Enforcer Example #3 mvn clean install –Denforcer.skip=true <project> <build> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0</version> </plugin> </build> </project>

  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 <project> ... <profiles> <profile> <id>enforcer</id> <activation/> <properties> <enforcer.skip>false</enforcer.skip> </properties> </profile> </profiles> </project>

  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

More Related