APACHE MAVEN Robert Scholte ( @rfscholte ) Developer vs. Maven? - - PowerPoint PPT Presentation

apache maven
SMART_READER_LITE
LIVE PREVIEW

APACHE MAVEN Robert Scholte ( @rfscholte ) Developer vs. Maven? - - PowerPoint PPT Presentation

WHEN FIGHTING APACHE MAVEN Robert Scholte ( @rfscholte ) Developer vs. Maven? Feels like Terminator 1 Should be Terminator 2 Developer with Maven! Feels like Terminator 1 Should be Terminator 2 Reason for a fight? #fail Setup (no


slide-1
SLIDE 1

WHEN FIGHTING APACHE MAVEN…

Robert Scholte ( @rfscholte )

slide-2
SLIDE 2

Developer vs. Maven?

Feels like Terminator 1 Should be Terminator 2

slide-3
SLIDE 3

Developer with Maven!

Feels like Terminator 1 Should be Terminator 2

slide-4
SLIDE 4

Reason for a fight? #fail

■ Setup (no plug ‘n’ play) ■ Adding/removing code/plugins/… ■ Suddenly broken

slide-5
SLIDE 5

The situation

■ An unknown huge multilevel Maven Multimodule Project ■ We suddenly have a FAILURE: – CI Server – Maven Commandline – IDE

slide-6
SLIDE 6

Is it structural?

slide-7
SLIDE 7

IF YOU CANNOT REPRODUCE THE ISSUE, THEN IT IS NOT A BUG

slide-8
SLIDE 8

Analysis

Options tions Descrip scription ion

  • v,--version

Display version information

  • V,--show-version

Display version information WITHOUT stopping build

  • e,--errors

Produce execution error messages

  • X,--debug

Produce execution debug output

slide-9
SLIDE 9

Most likely causes

■ Your project / code :P ■ Maven Plugin ■ External Tool (java, javac, javadoc, …) ■ Maven

slide-10
SLIDE 10

If message doesn’t help

■ Google ■ Stack Overflow ■ Documentation ■ Issue management system

slide-11
SLIDE 11

Isolate the issue

mvn <phase> -pl :<artifactId> -am

Options

  • ns

Descr cript ption ion

  • pl,--projects <arg>

Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path

  • am,--also-make

If project list is specified, also build projects required by the list

  • amd,--also-make-

dependents If project list is specified, also build projects that depend on projects on the list

slide-12
SLIDE 12

In case of external code: Sometimes reading code is enough

■ Github ■ JXR pages

slide-13
SLIDE 13

In search of regression with GIT

slide-14
SLIDE 14

GIT bisect

slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19

Most likely solution

■ Fix your code :P ■ Upgrade to a more recent version – Dependencies – Plugins ■ Patch / fix others code

slide-20
SLIDE 20

No more fighting

Let’s go for quick and dirty

slide-21
SLIDE 21

■ The pom is a strict XML configuration file ■ Still… people can be VERY creative

slide-22
SLIDE 22

#1 Extending parent pattern

<parent> <groupId>com.acme.product</groupId> <artifactId>parent</artifactId> <version>9</version> </parent> <artifactId>parent</artifactId> <version>10</version>

slide-23
SLIDE 23

Discovery

■ ModelValidator ■ Check for circular references

slide-24
SLIDE 24

Why Dirty?

■ Increase number of downloads ■ Getting Effective Model is complex process

slide-25
SLIDE 25

#2 Replacing pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <configuration> <pomFile File>cus custom.

  • m.po

pom</ </pom pomFil File> > </configuration> </plugin>

slide-26
SLIDE 26

Discovery

■ Code refactoring to support – installAtEnd – deployAtEnd

slide-27
SLIDE 27

Why Dirty?

■ No guarantee pom is valid

slide-28
SLIDE 28

Solution

■ Introduction flatten-maven-plugin – “transforms” original pom.xml – Can apply effective pom elements – Can remove elements ■ Experience will be used in Maven4 ■ Experimental feature likely in Maven 3.7.0 – maven.experimental.buildconsumer

slide-29
SLIDE 29

#3 Bind to none-phase

■ Disable predefined or inherited plugin executions ■ E.g. replace surefire with junit-platform-maven-plugin

slide-30
SLIDE 30

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <executions> <execution> <id>default-test</id> <phase>none</phase> </execution> </executions> </plugin>

slide-31
SLIDE 31

Why dirty?

“You should always listen to your parent” (that’s why I don’t like structural ‘skipping’)

slide-32
SLIDE 32

#4 Sharing local repo

Slow wifi / connection Workshop that requires more plugins/dependencies than expected Solution: memorystick ?!?!

slide-33
SLIDE 33

Mock Repository Manager

  • rg.codehaus.mojo:mrm-maven-plugin:run

mrm:run

slide-34
SLIDE 34

When going for quick and dirty…

■ Commandline arguments ■ Pom.xml

slide-35
SLIDE 35

You have one custom requirement

.. But there’s no maven-plugin for it ( and don’t want to write one... ) Inside pom execution:

  • maven-antrun-plugin
  • Executes Ant scripts
  • maven-scripting-plugin
  • Uses the Scripting API (JSR223)
  • exec-maven-plugin
  • Executes commandline or Java’s main(args)
slide-36
SLIDE 36

You need to manipulate Maven

■ Maven Extensions ■ Custom Maven Builder

slide-37
SLIDE 37

Understanding properties

■ Project ■ Settings (via profile properties) ■ System Properties ■ Commandline ( -Dkey=value )

slide-38
SLIDE 38

testFailureIgnore

Name Type Since Descr crip ipti tion

  • n

<testFailureIgnore> boolean

  • Set this to "true" to ignore a failure during
  • testing. Its use is NOT RECOMMENDED, but

quite convenient on occasion. Defaul ult t value e is: false. User property ty is: maven.test.failure.ignore.

slide-39
SLIDE 39

Replace default value

<properties> <maven.test.failure.ignore>true</maven.test.failure.ignore> </properties>

slide-40
SLIDE 40

Replace expression

<properties> <surefire.failureIgnore>false</surefire.failureIgnore> </properties> … <configuration> <testFailureIgnore> ${surefire.failureIgnore} </ testFailureIgnore> </configuration>

slide-41
SLIDE 41

Replace with constant

<configuration> <testFailureIgnore>false</testFailureIgnore> </configuration>

slide-42
SLIDE 42

Making friends

<configuration> <skipTests>false</skipTests> </configuration>

slide-43
SLIDE 43

The ‘evil’ jenkinsci maven-plugin

■ Why does it continue after a failed test??? ■ h.m.r.SurefireArchiver L87-L114

slide-44
SLIDE 44

Commandline arguments

What will happen when you execute ‘mvn deploy -DjavaVersion=13’ ?

slide-45
SLIDE 45

spring-boot-dependencies

What will happen when you execute ‘mvn deploy -Dspring.version=5.1.0.RELEASE’ ?

slide-46
SLIDE 46

“ARGUMENTS SHOULD NEVER HAVE EFFECT ON THE CREATED ARTIFACTS”

slide-47
SLIDE 47

Clean Install

■ Maven is about convention of configuration ■ If the convention was ‘clean install’, you should simply execute ‘mvn’

slide-48
SLIDE 48

Clean Install is not quick, just dirty

Clean lifecycle

Pha hase se Bindi ding ng pre-clean clean clean:clean (remove target directory) post-clean

slide-49
SLIDE 49

Clean

■ Delete and re-place (same) files is waste of resources ■ Most maven-plugins are aware if they must execute their task Avoid “clean”

slide-50
SLIDE 50

Clean Install is not quick, just dirty

Build / default lifecycle

Phase se Bind nding ing (for every packaging ging) … install install:install (copy artifact to local repo) deploy deploy:deploy (upload to remote repo)

slide-51
SLIDE 51

Install

Maven 2:

  • Not aware of ‘reactor’
  • Dependencies had to exist in local repo.

Maven 3:

  • ‘reactor’ aware
  • No need for ‘install’ anymore
slide-52
SLIDE 52

Avoid Clean, Avoid Install

Introducing the Maven CI Extension

slide-53
SLIDE 53

Ultimate hack:

just fork and re-version

Ensure no conflicts with official future versions e.g. 3.6.3-rfscholte-SNAPSHOT

slide-54
SLIDE 54

Up for Grabs

■ ~60-80% of Java Project/Developers use Maven ■ The Apache Maven Project holds ~95 (sub)projects ■ Maintained by ~5-10 active volunteers (No Company!) ■ Let’s restore the balance! ■ https://s.apache.org/up-for-grabs_maven ■ https://maven.apache.org/guides/development/guide-committer-school.html

slide-55
SLIDE 55

THANK YOU AND HAPPY HACKING!