Slide 1

Slide 1 text

Getting more out of Maven

Slide 2

Slide 2 text

Getting more out of Maven Andres Almiray 🐘 @aalmiray πŸ¦‹ @andresalmiray.com 🌐 www.andresalmiray.com Seasoned Sourceror Marit van Dijk @maritvandijk.bsky.social πŸ¦‹ @MaritvanDijk77 🐦 www.maritvandijk.com 🌐 Senior Developer Advocate

Slide 3

Slide 3 text

Agenda ● ● ● ● ● ● ● ● ● Getting started Maven wrapper Maven Lifecycle & Goals Inheritance Effective pom Profiles Enforcer plugin Dependency & plugin management Dealing with vulnerabilities

Slide 4

Slide 4 text

Getting started ● Creating a new project β—‹ β—‹ β—‹ From scratch Using a framework starter Using an archetype https://www.jetbrains.com/help/idea/maven-support.html β–Ά

Slide 5

Slide 5 text

New Java project ● Select Build system: Maven https://www.jetbrains.com/help/idea/maven-support.html#create_new_maven_project

Slide 6

Slide 6 text

Spring boot project ● ● ● Uses start.spring.io Default: Gradle - Groovy Select Build system: Maven

Slide 7

Slide 7 text

Maven archetype https://www.jetbrains.com/help/idea/maven-support.html#maven_archetype

Slide 8

Slide 8 text

Maven wrapper ● ● ● Provision a specific version of Maven Reduce build variance Increase reproducibility mvn wrapper:wrapper -Dmaven=3.9.16 β–Ά

Slide 9

Slide 9 text

How do you build your project?

Slide 10

Slide 10 text

mvn verify FTW

Slide 11

Slide 11 text

mvn verify FTW

Slide 12

Slide 12 text

mvn verify FTW

Slide 13

Slide 13 text

Maven Lifecycle & Goals ● ● ● ● Maven runs a build by executing steps in order Maven has a set of predefined lifecycle phases: e.g. clean, verify, install, … Goals are provided by plugins Goals are typically bound to a phase For example: The maven-compiler-plugin provides a `compile` goal that’s bound to the `compile` phase. https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Running goals - Run goals directly from the terminal Run goals in the IDE - From the Maven tool window From Run Configurations From Run Anything (βŒƒβŒƒ on macOS) / Ctrl+Ctrl on Windows/Linux) β–Ά

Slide 16

Slide 16 text

Terminal

Slide 17

Slide 17 text

Maven tool window ● ● Run lifecycle phases Basic phases only

Slide 18

Slide 18 text

Maven tool window ● Options

Slide 19

Slide 19 text

Maven tool window ● All phases

Slide 20

Slide 20 text

Run Configurations ● ● Right-click lifecycle phase Modify Run Configuration… https://www.jetbrains.com/help/idea/run-debug-configuration.html

Slide 21

Slide 21 text

Run Configurations ● ● Store as project file (to save) Modify Options

Slide 22

Slide 22 text

Run Anything ● Run Anything (βŒƒβŒƒ on macOS / Ctrl+Ctrl on Windows/Linux) https://www.jetbrains.com/help/idea/running-anything.html

Slide 23

Slide 23 text

Run Anything ● Maven Goals

Slide 24

Slide 24 text

Maven in IntelliJ IDEA ● ● ● ● IntelliJ IDEA supports Maven 3.1 and up Default bundled Maven version is 3.9.16 (in IntelliJ IDEA 2026.2) Use bundled version, wrapper, or point to installed version. Maven 4 support is already available from IntelliJ IDEA 2025.1 β—‹ Maven 4 is currently at rc-6 https://www.jetbrains.com/help/idea/maven-support.html

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

mvn verify FTW

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

https://bsky.app/profile/maritvandijk.bsky.social/post/3mpq47bo5dd2r

Slide 34

Slide 34 text

Inheritance ● ● ● ● Super pom Parent / child Order of resolution How values are propagated down the chain

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Effective pom ● Full project object model result for your project ● Generate effective pom on command line: β—‹ mvn help:effective-pom -Dverbose=true https://maven.apache.org/plugins/maven-help-plugin/effective-pom-mojo.html β–Ά

Slide 37

Slide 37 text

Profiles ● ● ● Can enhance default configuration of your build Add new sections, or override existing ones When you have plugins that should not be part of the main execution, e.g. β—‹ β—‹ β—‹ β—‹ Generate JavaDoc and sources jars Running quality gate checks Enable/disable a test module under certain conditions Publish to Maven Central https://maven.apache.org/guides/introduction/introduction-to-profiles.html β–Ά

Slide 38

Slide 38 text

Enforcer plugin ● ● Reproducibility Verify invariants & restrictions Control environmental constraints: ● ● ● ● Maven version JDK version Dependencies (semver, duplicates, snapshots, bytecode version, etc) and more https://maven.apache.org/enforcer/maven-enforcer-plugin/

Slide 39

Slide 39 text

Enforcer plugin

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

extra-enforcer-rules ● Add extra rules β—‹ EnforceBytecodeVersion β—‹ BanCircularDependencies β—‹ BanDuplicateClasses https://www.mojohaus.org/extra-enforcer-rules/

Slide 42

Slide 42 text

Extra rules extra-enforcer-rules β–Ά

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Dependency & plugin management ● ● ● Adding dependencies Managing dependencies Finding and resolving conflicts β–Ά

Slide 47

Slide 47 text

Dependency & plugin management ● Adding dependencies β—‹ IDE provides code completion for dependencies

Slide 48

Slide 48 text

Dependency & plugin management ● Adding dependencies β—‹ IDE provides code completion for dependencies (from cloud ☁and local cache 🏠)

Slide 49

Slide 49 text

Dependency & plugin management ● Managing dependencies & plugins β—‹ β—‹ Maven commands for dependencies β–  Overview of dependencies: `./mvnw dependency:tree` β–  Check for dependency updates: `./mvnw versions:display-dependency-updates` β–  Check for plugin updates: `./mvnw versions:display-plugin-updates` IDE: β–  Maven tool window: Dependencies β–Ά

Slide 50

Slide 50 text

Overview of dependencies: `./mvnw dependency:tree`

Slide 51

Slide 51 text

Check for updates: `./mvnw versions:display-dependency-updates`

Slide 52

Slide 52 text

Check for updates: `./mvnw versions:display-plugin-updates`

Slide 53

Slide 53 text

Dependency & plugin management ● Managing dependencies & plugins β—‹ β—‹ Maven commands for dependencies IDE: β–  Maven tool window: Dependencies β–Ά

Slide 54

Slide 54 text

Dependency conflicts ● Finding and resolving conflicts β—‹ β—‹ Maven commands β–  Overview of dependencies: `./mvnw dependency:tree` β–  Show the conflict using the enforcer (if configured): ● ./mvnw -f pom-enforced.xml initialize ● ./mvnw -f pom-enforced.xml enforcer:enforce@check IDE: β–  Finding and resolving conflicts: https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#dependency_analyzer β–Ά

Slide 55

Slide 55 text

./mvnw -f pom-enforced.xml initialize β–Ά

Slide 56

Slide 56 text

./mvnw -f pom-enforced.xml enforcer:enforce@check β–Ά

Slide 57

Slide 57 text

Dependency conflicts ● Finding and resolving conflicts β—‹ β—‹ Maven commands IDE: β–  Finding and resolving conflicts: Dependency analyzer https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#dependency_analyzer β–Ά

Slide 58

Slide 58 text

Dependency conflicts ● Finding and resolving conflicts β—‹ β—‹ Maven commands IDE: β–  Finding and resolving conflicts: https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#dependency_analyzer

Slide 59

Slide 59 text

Vulnerabilities ● ● Scan for known vulnerabilities Remediate by upgrading (if available / possible) ● Help in the IDE β—‹ https://www.jetbrains.com/help/idea/package-analysis.html β–Ά

Slide 60

Slide 60 text

Vulnerabilities Dependencies with known vulnerabilities are highlighted in the pom.xml β–Ά

Slide 61

Slide 61 text

Vulnerabilities Quickfix to update to unaffected version - if available β–Ά

Slide 62

Slide 62 text

Vulnerabilities Usage of vulnerable API is highlighted

Slide 63

Slide 63 text

Find usage of vulnerable API ● Run inspection by name: Vulnerable API Usage

Slide 64

Slide 64 text

Vulnerabilities Inspection to Go to file with declared dependency (and update it there to unaffected version - if available)

Slide 65

Slide 65 text

Vulnerabilities Overview of Vulnerable Dependencies ● ● Problem tool window Vulnerable Dependencies tab

Slide 66

Slide 66 text

Vulnerabilities Known vulnerabilities ● ● Severity Details

Slide 67

Slide 67 text

Summary ● ● ● ● Your tools (Maven, IntelliJ IDEA) can make you more productive Don’t blindly trust your tools; understand how they work & their limitations Provide feedback if something is missing Make sure the build works with Maven alone

Slide 68

Slide 68 text

Slides & more https://maritvandijk.com/presentations/getting-more-out-of-maven/

Slide 69

Slide 69 text

Thank you! Andres Almiray 🐘 @aalmiray πŸ¦‹ @andresalmiray.com 🌐 www.andresalmiray.com Seasoned Sourceror Marit van Dijk @maritvandijk.bsky.social πŸ¦‹ @MaritvanDijk77 🐦 www.maritvandijk.com 🌐 Senior Developer Advocate