pimp my build - oracle · bitstrips skitch atlassian sjug terence pete questions? pimp my build...
TRANSCRIPT
PIMP MY BUILD
Matt Quail &Conor MacNeill TS-5596
2008 JavaOneSM Conference | java.sun.com/javaone | 2
2008 JavaOneSM Conference | java.sun.com/javaone | 3
Your Build Sucks <!-- any parameters passed by ant to JVM to be used by Junit tests (e.g. path to Perforce executables) --> <property name="junit.jvmargs" value=""/> <property name="p4d.exe" value=""/> <property name="p4.exe" value=""/>
<fileset id="jetty.build.fileset" dir="${jetty.dir}"> <include name="${maven.dependencies.dir}/servlet-api-2.5-*.jar" /> <include name="${maven.dependencies.dir}/jetty-6.1.*.jar" /> <include name="${maven.dependencies.dir}/jetty-util-6.1.*.jar" /> <include name="${maven.dependencies.dir}/jsp-2.1*.jar" /> <include name="${maven.dependencies.dir}/jsp-api-2.1*.jar" /> <include name="${maven.dependencies.dir}/jetty-ajp-6.1*.jar" /> </fileset>
<fileset id="shaj.fileset" dir="${shaj.dir}" includes="*.jar"/>
<fileset id="svnkit.fileset" dir="${maven.dependencies.dir}"> <include name="**/svnkit*.jar"/> <include name="**/ganymed*.jar"/> <include name="**/jna*.jar"/> <include name="**/sqlitejdbc*.jar"/> </fileset>
2008 JavaOneSM Conference | java.sun.com/javaone | 4
In this talk you might learn
Some ways to improve your Ant buildHow to make your Maven build work (maybe)Maintainability strategiesFun things to try
2008 JavaOneSM Conference | java.sun.com/javaone | 5
Ground Rules
We’re Ant Centric Applies to Maven builds as well
If you use Make, leave now ;)
We are not trying to convert you.
2008 JavaOneSM Conference | java.sun.com/javaone | 6
#1: Use Imports
emo
2008 JavaOneSM Conference | java.sun.com/javaone | 7
Import Benefits
se Imports to modularize your build
ove all the targets that do not change across projects into a common module
mport the module into your build and override as appropriate
eparate what your build needs to do from the details of how it’s done
2008 JavaOneSM Conference | java.sun.com/javaone | 8
#2: Use Macros and Presets
ive off common groups of operations into macros
ake your build simpler, easier to read
es, <xml> does suck for readability and usability• Don’t tell us - Terence Parr already did• Really
2008 JavaOneSM Conference | java.sun.com/javaone | 9
Macro Example - .NET build
macrodef name="devenv">
<attribute name="solution"/>
<attribute name="config"/>
<sequential>
<exec taskname="devenv” executable=“devenv.com”vmlauncher="false">
<arg value="@{solution}"/>
<arg value="/build"/>
<arg value="@{config}"/>
</exec>
</sequential>
</macrodef>
<devenv solution="CloverAll.sln" config="Debug"/>
2008 JavaOneSM Conference | java.sun.com/javaone | 10
#3: Don’t Build Stuff you don’t Need
se the <uptodate> task
t is complex• Invest the time to get it right in the build• Keep you and your team productive• The build will remember how to do it• Put it in a macro and make its use simple
se <outofdate> from ant-contrib• Even better
2008 JavaOneSM Conference | java.sun.com/javaone | 11
#4: Spice Up Your Build
emo
2008 JavaOneSM Conference | java.sun.com/javaone | 12
Build Fun
dd a splash image• Associate it with a sprint, a scrum, an iteration, a
blast, whatever you call it.• It’s a bit of fun• Add some stupid cat image
dd some sound• You can watch youtube while your build does its
thing• At least this way you come back to your build when
it’s done• Add the blame train toot
2008 JavaOneSM Conference | java.sun.com/javaone | 13
Clover Splash Timeline
2008 JavaOneSM Conference | java.sun.com/javaone | 14
2008 JavaOneSM Conference | java.sun.com/javaone | 15
2008 JavaOneSM Conference | java.sun.com/javaone | 16
2008 JavaOneSM Conference | java.sun.com/javaone | 17
Censored
2008 JavaOneSM Conference | java.sun.com/javaone | 18
Censored
2008 JavaOneSM Conference | java.sun.com/javaone | 19
2008 JavaOneSM Conference | java.sun.com/javaone | 20
2008 JavaOneSM Conference | java.sun.com/javaone | 21
2008 JavaOneSM Conference | java.sun.com/javaone | 22
Censored
2008 JavaOneSM Conference | java.sun.com/javaone | 23
Maven Tips
2008 JavaOneSM Conference | java.sun.com/javaone | 24
Maven Growl Notifications
Mac OSX growlnotify for your maven builds
#! /bin/shmvn $* | awk '{ print; if($0 ~ ".*Downloading.*") system("/usr/local/bin/growlnotify -n mavenError -t Maven Downloading -m\""$0 "\"") if($0 ~ ".*ERROR.*") system("/usr/local/bin/growlnotify -n mavenError -t Maven Error -m\""$0 "\"") } END {system("/usr/local/bin/growlnotify -n mavenComplete -t Maven -m \"Build Complete\"")}'
2008 JavaOneSM Conference | java.sun.com/javaone | 25
#5: Don't Be Afraid to write Tasks
es, tasks are code, but we’re coders.
on’t separate your team into builders and coders• Everyone should know how the build works• The build should not be precious or off-limits
•But …
2008 JavaOneSM Conference | java.sun.com/javaone | 26
2008 JavaOneSM Conference | java.sun.com/javaone | 27
#6: Use Scripts
Ant let’s you define tasks with scripts <scriptdef name="versiondays" language="javascript"> <attribute name="propname"/> <![CDATA[ now = new java.util.Date(); millis = now.getTime(); days = millis / 86400000 - 10957; project.setProperty(attributes.get("propname"), days.toFixed(0).toString()); ]]> </scriptdef>
<versiondays propname="version.day"/>
2008 JavaOneSM Conference | java.sun.com/javaone | 28
#7: Use Conditional Tasks
Yes, you should try to be declarative, but<if> <os family="mac"/> <then> <property name="gwt.vmargs" value="-XstartOnFirstThread"/> </then> <else> <property name="gwt.vmargs" value=""/> </else> </if>
Use ant-contrib tasks
2008 JavaOneSM Conference | java.sun.com/javaone | 29
#8: Don't do One-Off Analysis
Your build is a way of recording how to do a set of complex operations.
Heaps of Analysis tool out there - USE THEM◦ FindBugs, CheckStyle, PMD, Clover, etc◦ Put them in your build◦ ant checkstyle is easy to remember◦ mvn lifecycly goaly:thingy
Ok, I can’t remember it but it’s sorta easy ;)
2008 JavaOneSM Conference | java.sun.com/javaone | 30
#9: Document Your Build
dd descriptions
dd comments
se the –target_name convention for private targets• No, it’s not perfect• Yes, it does work• It’s called an idiom
2008 JavaOneSM Conference | java.sun.com/javaone | 31
More Doing Things
emember your build is where you document the tasks in your projects• Run tests• Run the build• Create the license file• Generate Coverage reports• Yes, that is a shameless plug
• Attach debuggers, run profilers
ive newbies a leg up• You can add a few newbie surprises too
2008 JavaOneSM Conference | java.sun.com/javaone | 32
Continuous integration
ou are doing continuous integration right?!• If you are not please tell me why• Actually just tell me the name of your product
• Controlled Build Environment• Automated Testing and Reporting• Its easy because it is already in your build file
2008 JavaOneSM Conference | java.sun.com/javaone | 33
Testing
o I need to say anything here?
2008 JavaOneSM Conference | java.sun.com/javaone | 34
Repetitive Tasks
utomate them
on’t ever type a long series of commands twice
ut them in the build to remember them
2008 JavaOneSM Conference | java.sun.com/javaone | 35
#10 Maven Best Practice Tips
Use a remote repository proxy• Archiva
Create a local repository for private artifacts• Your own artifacts• Missing third party artifacts
Local repository for public artifacts• Artifacts you are making available
You need to manage your build infrastructure
2008 JavaOneSM Conference | java.sun.com/javaone | 36
Thanks
BitstripsSkitchAtlassianSJUGTerencePete
Questions?
Pimp my BuildConor MacNeill & Matt Quail
TS-5596
Speaker’s logo here (optional)