Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Maven POM demistified - enhance your build

C59c6666e76977dde33948515fdb3a90?s=47 ElmarDott
November 27, 2021

Maven POM demistified - enhance your build

Since more than a decade Apache Maven is one of the most convenient Build and Reporting tools for Java projects. The success of this tool is quit more than just being a build tool. It solves problems in a simple manner. As developer you need run your Maven Build several times, but often the knowledge is missing how to manipulate the build without change the build logic called POM. I will show some tricks how to solve problems when your Maven got stucked. In this presentation I cover regular developer issues and how to overcome them. Because a well working build is more than just a bit of DevOps techniques.

--------------------------------------------------------------------------------------------------
Homepage : https://elmar-dott.com
AnchorFM : https://anchor.fm/elmar-dott
Twitter - https://twitter.com/ElmarDott
GitHub - https://github.com/ElmarDott
Lbry - https://lbry.tv/@elmar.dott:8
BitChute - https://www.bitchute.com/channel/3IyCzKdX8IpO/
--------------------------------------------------------------------------------------------------

C59c6666e76977dde33948515fdb3a90?s=128

ElmarDott

November 27, 2021
Tweet

Transcript

  1. Jc on f 2021 P e r u on l

    i n e © 2021 ElmarDott Maven POM demistified - enhance your build
  2. © 2021 j Con f P e r u 2021

    Sp e a k e r El ma r Do t t (M. Schulz) studied at HS Merseburg, Germany, computer science and holds an engineers degree in software engineering. He tweets regularly about several technical topics. The main topics in his field of work are Build and Configuration Management, Software Architecture and Release Management. About more than 15 years he is working in different large Web Application projects all over the world. He is an independent consultant / trainer. To share his knowledge he gives talks on conferences, if he is not writing on a new article about software engineering. https://elmar-dott.com + Consultant + Writer + Speaker + Trainer +
  3. © 2021 j Con f P e r u 2021

    Ag e nd a Maven basics the build lifecycle project structure project object model dependency management samples
  4. © 2021 j Con f P e r u 2021

    Te rm s Artifact: is a independent pice of software like a library, module or plugin. Life-Cycle: Maven has three different Lifecycles for software development: Build, Clean and Site. Phase: divides the Build-Lifecycle into 23 parts. The Lifecycle walk through the phases in a defined ordering. Goal: are defined by a Maven-Plugin (MOJO) and describe a sub task inside the plugin. Dependencies are Artifacts which stored in a local or remote Repository for reuse in other projects.
  5. © 2021 j Con f P e r u 2021

    Con c e p t s • Don‘t repeat yourself (DRY) • Convention over Configuration (CoC) • Keep it simple, stupid! (KISS) https://maven.apache.org
  6. © 2021 j Con f P e r u 2021

    Pr o j e c t St r u c t u r e /subfolder : module pom.xml : module-pom /src /main /filter : token replacement /java : source /resources : non-source – binary /resources-filtered : resources for token replacement /webapp : web.xml etc. /test /java : test sources /resources : test non source - binary /resources-filtered : test resources /site : reporting /resources /site.xml : site descriptor /target : build output /pom.xml project view in NetBeans
  7. © 2021 j Con f P e r u 2021

    POM Va r i a t i on s SUPER POM REACTOR POM PROJECT POM PARENT POM MODULE POM POM WAR EAR ABSTRACT POM JAR / WAR / EAR POM
  8. © 2021 j Con f P e r u 2021

    Samp l e POM 01: <?xml version="1.0" encoding="UTF-8"?> 02: <project> 03: <modelVersion>4.0.0</modelVersion> 04: <parent> 05: <groupId>org.sample</groupId> 06: <artifactId>parent-pom</artifactId> 07: <version>1.0</version> 08: </parent> 09: <groupId>org.sample</groupId> 10: <artifactId>project-name</artifactId> 11: <version>1.0-SNAPSHOT</version> 12: <packaging>pom | jar | war | ear | zip</packaging> 13: <modules> 14: <module>subfolder</module> 15: </modules> 08: </project>
  9. © 2021 j Con f P e r u 2021

    De e nd e n c y Man a g e m e n t 01: <?xml version="1.0" encoding="UTF-8"?> 02: <project> 03: <modelVersion>4.0.0</modelVersion> 04: <groupId>org.sample</groupId> 05: <artifactId>project-name</artifactId> 06: <version>1.0-SNAPSHOT</version> 07: <packaging>jar</packaging> 08: <depenedencies> 09: <depenedency> 10: <groupId>junit</groupId> 11: <artifactId>junit</artifactId> 12: <version>4.13</version> 13: <scope>test</scope> 14: </depenedency> 15: </depenedencies> 16: </project>
  10. © 2021 j Con f P e r u 2021

    Bu i l d L i f e c y c l e Phase Description 15 - test run tests in a configured test framework 17 - package package the compiled code in a distributive format 21 – verify execute integration test 22 – install copy the artifact to a local repository 23 – deploy upload the artifact to a remote repository Command Line: $~ mvn <phase>:<plugin>:<goal> https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
  11. © 2021 j Con f P e r u 2021

    t h e Commad l i n e % default phases in debug mode $~ mvn {clean | site | package | verify | install | deploy} -X % the preferred way $~ mvn clean install → $~ mvn verify % call a specific plugin goal $~ mvn versions:display-plugin-updates % call profiles $~ mvn package -P release javadoc % overwrite properties $~ mvn package -DskipTests=true % alternative settings.xml $~ mvn package -S settings.xml
  12. © 2021 j Con f P e r u 2021

    Samp l e s practical demonstration on Ubuntu MATE & NetBeans IDE 01 > token replacement :: database configuration 02 > compiler warnings :: quality 03 > executable jar files 04 > enforcement :: release builds 05 > Unit & Integration testing 06 > working with web apps & multi module projects 07 > BOM – Bill of Materials :: dependency management „ A Fool with a Tool is still a fool.“ Grady Booch https://github.com/ElmarDott/SamplesAndTrainings/tree/master/mvn-samples
  13. © 2021 j Con f P e r u 2021

    Cr e d e n t i a l s --------------------------------------------------------- Homepage : https://elmar-dott.com GitHub : https://github.com/ElmarDott AnchorFM : https://anchor.fm/elmar-dott Twitter : https://twitter.com/ElmarDott Speaker Deck : https://speakerdeck.com/elmardott Lbry : https://lbry.tv/@elmar.dott:8 BitChute : https://www.bitchute.com/channel/3IyCzKdX8IpO/ --------------------------------------------------------- Danke / thank you / Gracias
  14. None