Groovy Maven Builds
-
Upload
goldin-evgeny -
Category
Technology
-
view
130 -
download
6
description
Transcript of Groovy Maven Builds
11
Evgeny GoldinThomson Reuters@evgeny_goldin
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
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
44
About this session:
Maven can be made better! .. especially when you use GroovyWe’ll see how:
GMavenPolyglot MavenGroovy MOJOs + Demo
55
Maven and Gradle
66
Gradle - dynamic build applications.
Maven - repeatable build processes.
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
88
Is the game over? Or can builds become applications?
99
Use case – Build Metadata
1010
http://goo.gl/i0ldH
Ant: ~60 LOC (100 total)
3 files
1111
http://goo.gl/GdS6y
Groovy: ~10
LOC (30 total)
1212
Compiles Groovy codeExecutes Groovy codeGenerates Java Stubs, required for MOJOsJoin Compilation with Java (sort of)http://pinboard.in/u:evgenyg/t:gmaven/
1313
<goal>execute</goal>
Runs Groovy codeRuns Groovy scriptRuns Groovy class
1414
http://goo.gl/8DOe2
Get IDE support back!
1515
<goal>execute</goal>
Runs Groovy codeRuns Groovy scriptRuns Groovy classMavenProject MavenSessionMaven’s “ServletContext”
1616
MavenProject – Static Info
http://goo.gl/3Ve31CoordinatesPropertiesArtifactsDependenciesBasedirRemote repositories
1717
MavenSession – Runtime Info
http://goo.gl/Kh8iLCurrent MavenProjectBuild start timeUser propertiesSystem propertiesGoalsLocal repository
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
1919
Use case – Build Metadata
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>
2121
http://evgeny-goldin.com/wiki/Gradle-about-plugin
apply plugin: 'about‘
...
about { dumpDependencies = true }
...
assemble.doLast { about.execute() }
2222
something.jar/META-INF/about.txt
2323
2424
?
2525
Polyglot Maven
https://docs.sonatype.org/display/PMAVEN/https://github.com/sonatype/polyglot-mavengit clone + mvn clean installtranslate pom.xml pom.groovy
2626
http://goo.gl/U5eqr
2727
http://goo.gl/av0Dx
2828
Polyglot Maven
Groovy syntactic sugar to Maven POMCouldn’t find a way to
Attach a code to a lifecycleLocate MavenProject and MavenSession
2929
Polyglot Maven
“if” a model composition / plugin executionSpecify dynamic value when configuring a
pluginPut your own logic in POM“validate” phase
3030
Groovy MOJOs
ReusableMore exposure to Maven runtime
environmenthttp://pinboard.in/u:evgenyg/t:mojo/
3131
Use case – Duplicates
http://goo.gl/ZFRvp
3232
http://www.flickr.com/photos/rohdesign/3534506648/ (rohdesign.com)
https://github.com/evgeny-goldin/gmaven-samples
Duplicates Finder
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>
3434
http://evgeny-goldin.com/wiki/Gradle-duplicates-plugin
apply plugin: 'duplicates'
...
duplicates { configurations = [ 'compile', 'runtime' ] }
...
>gradle duplicates
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] =-=-
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] =-=-
3737
Groovy MOJOs
A Groovy class + @AnnoMojo
3838
Groovy MOJOs
A Groovy class + @AnnoMojoDynamic properties
http://goo.gl/UqBqn
3939
Groovy MOJOs
A Groovy class + @AnnoMojoDynamic properties
http://goo.gl/UqBqn
4040
Groovy MOJOs
A Groovy class + @AnnoMojoDynamic properties
http://goo.gl/xV73v
4141
Groovy MOJOs
A Groovy class + @AnnoMojoDynamic propertiesNew Maven properties
http://goo.gl/tEgQa
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
4343
mojo-executor
http://goo.gl/CT6AQ
4444
Groovy MOJOs
A Groovy class + @AnnoMojoDynamic propertiesNew Maven propertiesOther plugins can be extended or invokedThat’s how you deal with Maven!
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
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
4747
So ..
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
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
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 ..
5151
Maven Plugins
http://evgeny-goldin.com/wiki/Maven-pluginsmaven-copy-pluginmaven-jenkins-pluginmaven-assert-plugin maven-mail-pluginmaven-about-pluginduplicates-finder-plugin
5252
Maven Plugins
http://evgeny-goldin.com/wiki/Maven-pluginsmaven-copy-pluginmaven-jenkins-pluginmaven-assert-plugin maven-mail-pluginmaven-about-pluginduplicates-finder-plugin
5353
Gradle Plugins
http://evgeny-goldin.com/wiki/Gradle-plugins “About” plugin“Duplicates” plugin“CodeNarc” plugin
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/
5555