Read Time:3 Minute, 34 Second
So… as my understanding of how to get my little programming projects rolled out matures, I have discovered Apache Maven…. and it really is quite nice for getting everything I was doing manually for the projects, done automatically. Building, distributing, constructing a project reporting site, running tests (finally have some testing built into my apps), etc. All in all, a very useful all-inclusive tool. It has taken a little work to make everything run the way I was hoping it would run, but little by little, I’m getting there.
So far, I’ve been using the gwt-syntaxhighlighter project as my testbed for maven, with plans on rolling out the concepts/methods I’ve used there to also be applied to the gwt-fontface project, and finally the ShowSort app.
Since I decided to go with Google Code for where I have the project hosted, and picked Mercurial as my source control of choice, it has proven to produce some interesting hurdles along the way. First and foremost, getting maven configured to be able to generate a GWT module was interesting, as the “Maven Way” is to keep source code and compiled code separate in two different packaged jar files, but the GWT way is to have them together, so the GWT compiler can do its thing with the source code to generate the JavaScript code for GWT. This proved to be rather simple, with the Maven GWT Plugin as it can handle having the source code in a separate file from the compiled code, and make it work with GWT. However I still needed to build something that would work for non-maven people… so the Maven Assembly Plugin comes to the rescue, making an additional jar file with the necessary source files added into the compiled file. The GWT plugin also makes it so I can separate the “resource” files (the CSS, JavaScript, and .gwt.xml files needed for the final product) separate from the Java files, making it a little cleaner and easier to locate the java files I need to work on without a polluted directory structure.
Tying it all together with Maven’s SCM configuration, I was then able to have maven automatically push the new, updated source files to the source code repository whenever I release a new version. I use the SonaType OSS Maven artifact repository to release the jars into the Maven world, which is a nice convenient way for Maven users to be able to locate and use the gwt-syntaxhighlighter project and have it included into their own apps. Finally, I was able to rely on the Maven GWU Plugin to have it automatically upload the released jars up to the Google Code downloads. This means in one simple command, I can completely deploy the gwt-syntaxhighlighter project in an efficient and effective manner, getting the source code checked-in, and releasing the built jars into both the Maven central repository and into the Google Code downloads section for the project.
Finally, I tied in the Maven site generation system, which constructs a nice, simple website for the project. I have two sets of Java API documentation, the change log for the project, and a few other details all integrated into it, and have it all rigged up to be updated when I release a new version of the code.
Another thing Maven allowed for me to do, was to have a simple way to construct and run tests on the gwt-syntaxhighlighter module, checking to ensure that it works how I think it should be working. These tests end up being run automatically whenever I build the project, giving me a nice, comfortable feeling that the project will be running the way I hope it will be. Right now, the tests are probably not completely adequate, but I will be working over time to make them as robust as I can.
Since everything is tied directly into Maven, it should, theoretically, be possible for me to use any development environment (that supports Maven), so I’ll no longer need to worry about how the directory structure and set-up is for my project in Eclipse and then need to switch to NetBeans at some point or another… I can use either one at my leisure.