55
11 Evgeny Goldin Thomson Reuters @evgeny_goldin Groovy Maven Builds

Groovy Maven Builds

Embed Size (px)

DESCRIPTION

"Groovy Maven Builds" presentation from Gr8Conf, Copenhagen (May 19, 2011) It shows how Maven builds become more dynamic when Groovy power and flexibility is applied.

Citation preview

Page 1: Groovy Maven Builds

11

Evgeny GoldinThomson Reuters@evgeny_goldin

Groovy Maven Builds

Page 2: Groovy Maven Builds

22

Evgeny Goldin

Software Developer – 12 yearsDev : C++ => Perl => Java => Groovy /

ScalaCM : Ant => Maven => Gradle OS : Artifactory, TeamCity, JenkinsWrite for GroovyMag and Methods & ToolsMaven plugins, GCommons library

Page 3: Groovy Maven Builds

33

Maven state of affairs:

Maven is rarely used to its fullest potential“maven-antrun-plugin” is overusedNo community around plugins

http://maven.apache.org/pluginshttp://mojo.codehaus.org/plugins.html

Page 4: Groovy Maven Builds

44

About this session:

Maven can be made better! .. especially when you use GroovyWe’ll see how:

GMavenPolyglot MavenGroovy MOJOs + Demo

Page 5: Groovy Maven Builds

55

Maven and Gradle

Page 6: Groovy Maven Builds

66

Gradle - dynamic build applications.

Maven - repeatable build processes.

Page 7: Groovy Maven Builds

77

Maven makes it awkward to ..

“if” a model composition / plugin executionSpecify dynamic value when configuring a

pluginPut your own logic in POMModify existing plugins behaviorPass in-memory information between plugins

Page 8: Groovy Maven Builds

88

Is the game over? Or can builds become applications?

Page 9: Groovy Maven Builds

99

Use case – Build Metadata

Page 10: Groovy Maven Builds

1010

http://goo.gl/i0ldH

Ant: ~60 LOC (100 total)

3 files

Page 11: Groovy Maven Builds

1111

http://goo.gl/GdS6y

Groovy: ~10

LOC (30 total)

Page 12: Groovy Maven Builds

1212

Compiles Groovy codeExecutes Groovy codeGenerates Java Stubs, required for MOJOsJoin Compilation with Java (sort of)http://pinboard.in/u:evgenyg/t:gmaven/

Page 13: Groovy Maven Builds

1313

<goal>execute</goal>

Runs Groovy codeRuns Groovy scriptRuns Groovy class

Page 14: Groovy Maven Builds

1414

http://goo.gl/8DOe2

Get IDE support back!

Page 15: Groovy Maven Builds

1515

<goal>execute</goal>

Runs Groovy codeRuns Groovy scriptRuns Groovy classMavenProject MavenSessionMaven’s “ServletContext”

Page 16: Groovy Maven Builds

1616

MavenProject – Static Info

http://goo.gl/3Ve31CoordinatesPropertiesArtifactsDependenciesBasedirRemote repositories

Page 17: Groovy Maven Builds

1717

MavenSession – Runtime Info

http://goo.gl/Kh8iLCurrent MavenProjectBuild start timeUser propertiesSystem propertiesGoalsLocal repository

Page 18: Groovy Maven Builds

1818

GMaven

“if” a model composition / plugin executionSpecify dynamic value when configuring a

pluginPut your own logic in POMModify existing plugins behaviorPass in-memory information between plugins

Page 19: Groovy Maven Builds

1919

Use case – Build Metadata

Page 20: Groovy Maven Builds

2020

http://evgeny-goldin.com/wiki/Maven-about-plugin

<plugin>

<groupId>com.goldin.plugins</groupId>

<artifactId>maven-about-plugin</artifactId>

<version>0.2.3.4-about-fix</version>

</plugin>

Page 21: Groovy Maven Builds

2121

http://evgeny-goldin.com/wiki/Gradle-about-plugin

apply plugin: 'about‘

...

about { dumpDependencies = true }

...

assemble.doLast { about.execute() }

Page 22: Groovy Maven Builds

2222

something.jar/META-INF/about.txt

Page 23: Groovy Maven Builds

2323

Page 24: Groovy Maven Builds

2424

?

Page 25: Groovy Maven Builds

2525

Polyglot Maven

https://docs.sonatype.org/display/PMAVEN/https://github.com/sonatype/polyglot-mavengit clone + mvn clean installtranslate pom.xml pom.groovy

Page 26: Groovy Maven Builds

2626

http://goo.gl/U5eqr

Page 27: Groovy Maven Builds

2727

http://goo.gl/av0Dx

Page 28: Groovy Maven Builds

2828

Polyglot Maven

Groovy syntactic sugar to Maven POMCouldn’t find a way to

Attach a code to a lifecycleLocate MavenProject and MavenSession

Page 29: Groovy Maven Builds

2929

Polyglot Maven

“if” a model composition / plugin executionSpecify dynamic value when configuring a

pluginPut your own logic in POM“validate” phase

Page 30: Groovy Maven Builds

3030

Groovy MOJOs

ReusableMore exposure to Maven runtime

environmenthttp://pinboard.in/u:evgenyg/t:mojo/

Page 31: Groovy Maven Builds

3131

Use case – Duplicates

http://goo.gl/ZFRvp

Page 32: Groovy Maven Builds

3232

http://www.flickr.com/photos/rohdesign/3534506648/ (rohdesign.com)

https://github.com/evgeny-goldin/gmaven-samples

Duplicates Finder

Page 33: Groovy Maven Builds

3333

http://evgeny-goldin.com/wiki/Duplicates-finder-plugin

<plugin>

<groupId>com.goldin.plugins</groupId>

<artifactId>duplicates-finder-plugin</artifactId>

<version>0.2.3.4</version>

</plugin>

Page 34: Groovy Maven Builds

3434

http://evgeny-goldin.com/wiki/Gradle-duplicates-plugin

apply plugin: 'duplicates'

...

duplicates { configurations = [ 'compile', 'runtime' ] }

...

>gradle duplicates

Page 35: Groovy Maven Builds

3535

Maven PluginsDuplicates found in:

-=-= [org.codehaus.plexus:plexus-classworlds:jar:2.2.2:compile, classworlds:classworlds:jar:1.1:compile] =-=-

-=-= [commons-logging:commons-logging-api:jar:1.1:compile, commons-logging:commons-logging:jar:1.1.1:compile] =-=-

-=-= [nekohtml:xercesMinimal:jar:1.9.6.2:compile, xerces:xercesImpl:jar:2.8.1:compile] =-=-

-=-= [nekohtml:nekohtml:jar:1.9.6.2:compile, net.sourceforge.nekohtml:nekohtml:jar:1.9.9:compile] =-=-

-=-= [commons-beanutils:commons-beanutils:jar:1.8.0:compile, commons-collections:commons-collections:jar:3.2.1:compile] =-=-

Google GuiceDuplicates found in:

-=-= [com.google.inject:guice:jar:3.0-SNAPSHOT:compile, com.google.inject:guice:jar:no_deps:3.0-SNAPSHOT:compile] =-=-

Page 36: Groovy Maven Builds

3636

CodeNarcDuplicates found in:

-=-= [org.codenarc:CodeNarc:0.14, org.codehaus.groovy:groovy-all:1.7.5] =-=-

--- [org.codehaus.groovy.ast.expr.RegexExpression]

--- [org.codehaus.groovy.transform.powerassert.Value]

--- [org.codehaus.groovy.transform.powerassert.ValueRecorder]

Test CompileDuplicates found in:

-=-= [junit:junit-dep:4.8.2, junit:junit:4.8.2] =-=-

-=-= [org.hamcrest:hamcrest-core:1.2, junit:junit:4.8.2] =-=-

Page 37: Groovy Maven Builds

3737

Groovy MOJOs

A Groovy class + @AnnoMojo

Page 38: Groovy Maven Builds

3838

Groovy MOJOs

A Groovy class + @AnnoMojoDynamic properties

http://goo.gl/UqBqn

Page 39: Groovy Maven Builds

3939

Groovy MOJOs

A Groovy class + @AnnoMojoDynamic properties

http://goo.gl/UqBqn

Page 40: Groovy Maven Builds

4040

Groovy MOJOs

A Groovy class + @AnnoMojoDynamic properties

http://goo.gl/xV73v

Page 41: Groovy Maven Builds

4141

Groovy MOJOs

A Groovy class + @AnnoMojoDynamic propertiesNew Maven properties

http://goo.gl/tEgQa

Page 42: Groovy Maven Builds

4242

Groovy MOJOs

Other plugins can be extended or invokedTheir initialization though, may not work wellhttp://github.com/TimMoore/mojo-executor

http://goo.gl/tEgQa

Page 43: Groovy Maven Builds

4343

mojo-executor

http://goo.gl/CT6AQ

Page 44: Groovy Maven Builds

4444

Groovy MOJOs

A Groovy class + @AnnoMojoDynamic propertiesNew Maven propertiesOther plugins can be extended or invokedThat’s how you deal with Maven!

Page 45: Groovy Maven Builds

4545

Maven 3 vs. Maven 2

IE9 vs. IE6Maven 3: Aether, mojo-executor, better Mojo

supportMaven 3 Mojos will not run on Maven 2Maven 2 support will seriously hold you back

Page 46: Groovy Maven Builds

4646

Groovy MOJOs

“if” a model composition / plugin executionSpecify dynamic value when configuring a

pluginPut your own logic in POMModify existing plugins behaviorPass in-memory information between plugins

Page 47: Groovy Maven Builds

4747

So ..

Page 48: Groovy Maven Builds

4848

So ..GMaven - custom build behavior on any

phasePolyglot Maven is a Groovy syntactic sugar Groovy Mojos is the way to make it your

way

Page 49: Groovy Maven Builds

4949

So .. GMaven - custom build behavior on any

phasePolyglot Maven is a Groovy syntactic sugar Groovy Mojos is the way to make it your wayCreating build applications with Maven –

doable!Maven is not a solution, but a platform

Page 50: Groovy Maven Builds

5050

So .. GMaven - custom build behavior on any

phasePolyglot Maven is a Groovy syntactic sugar Groovy Mojos is the way to make it your wayCreating build applications with Maven –

doable!Maven is not a solution, but a platformWe don’t have to be limited by existing pluginsPerl, IDEA, Jenkins, jQuery, Grails, Gradle ..

Page 51: Groovy Maven Builds

5151

Maven Plugins

http://evgeny-goldin.com/wiki/Maven-pluginsmaven-copy-pluginmaven-jenkins-pluginmaven-assert-plugin maven-mail-pluginmaven-about-pluginduplicates-finder-plugin

Page 52: Groovy Maven Builds

5252

Maven Plugins

http://evgeny-goldin.com/wiki/Maven-pluginsmaven-copy-pluginmaven-jenkins-pluginmaven-assert-plugin maven-mail-pluginmaven-about-pluginduplicates-finder-plugin

Page 53: Groovy Maven Builds

5353

Gradle Plugins

http://evgeny-goldin.com/wiki/Gradle-plugins “About” plugin“Duplicates” plugin“CodeNarc” plugin

Page 54: Groovy Maven Builds

5454

Links

@evgeny_goldinhttp://evgeny-goldin.comhttp://pinboard.in/u:evgenyg/t:gmaven/http://pinboard.in/u:evgenyg/t:mojo/http://pinboard.in/u:evgenyg/t:maven3/

Page 55: Groovy Maven Builds

5555