Tweet your Project status with Maven and Groovy
That's essentially what I've done for the HTTPBuilder project, my solution for making the complexities of HTTP both simple and accessible from Groovy. HTTPBuilder automatically 'tweets' every time I publish a release as part of the build process.
I've been meaning to write this for a while and now that I've been beaten to the punch by an Ant/Java solution, it's motivated me to finally share this.
Thank you GMaven!
Maven and the GMaven plugin take care of the bulk of the work here. GMaven already has the capability to run a Groovy script when a certain build phase is executed in Maven. So, add a simple script that uses the Twitter REST API, et voila! You automatically tweet to your users every time a release (or snapshot) is deployed. How cool is that?The Script
The script itself is fairly simple -- at least, HTTPBuilder makes is easy -- thanks to OAuth integration and simple POST support. This takes care of the twitter authentication and message encoding:// Send a Twitter update when a release is made. Cool! import groovyx.net.http.RESTClient import static groovyx.net.http.ContentType.* @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1') twitter = new RESTClient( 'https://twitter.com/statuses/update.xml' ) twitter.auth.oauth pom.properties.'twitter.oauth.consumerKey', pom.properties.'twitter.oauth.consumerSecret', pom.properties.'twitter.oauth.accessToken', pom.properties.'twitter.oauth.secretToken' println "Sending tweet..." msg = "v${pom.version} has been released! (${new Date()}) http://goo.gl/VzuT #groovy" resp = twitter.post( body : [ status:msg, source:'httpbuilder' ], requestContentType : URLENC, contentType:TEXT ) println "Tweet response status: ${resp.statusLine}" println 'http://twitter.com/#!/httpbuilder/status/${resp.data.id.text()}' assert resp.statusLine.statusCode == 200Thanks to GMaven, you can get handy bits of build information (like the project version) from the 'pom' object that is automatically added to the script scope.
Maven Configuration
The Maven piece is equally simple:<build> <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>release</id> <phase>deploy</phase> <goals> <goal>execute</goal> </goals> <configuration> <source>${pom.basedir}/src/main/script/release_tweet.groovy</source> </configuration> </execution> </executions> </plugin> </build>