Greg Wilkins is the Chief Technical Officer (CTO) and one of the founding CEO of Webtide. He was also a founder and CEO of Mort Bay Consulting. Greg has deep knowledge of all facets of software development. He has, 22 years experience as a software developer, team leader, architect, trainer, and technical mentor in industry sectors ranging from telecommunications, finance, realtime computing to internet applications. He is closely involved with the open source movement, being the creator of the Jetty web container, a co-founder of Apache Geronimo, and a committer or contributor to a number of other open source projects. Greg sits on the JCP Servlet Expert Group and is active in the Open Ajax Alliance. Greg received his B.S. Computer Science Degree with 1st Class Honors from Sydney University, Australia. Greg has posted 11 posts at DZone. View Full User Profile

Dojo Toolkit Maven Repository

12.10.2008
| 11370 views |
  • submit to reddit

Using maven to build your project is a fantastic for managing your dependencies andavoiding having dependencies (and their dependencies) checked into yourown svn.  The only fly in the ointment, is projects that don't publishmaven artifacts, and the Ajax dojo toolkit has been one of these. Until now that is !

I have added a maven build to dojo and created maven repositories for snapshots and releases at:

These repositories contain artifacts for:

  • dojo toolkit release as a zip, tar.gz and tar.bz2

  • dojotoolkit packaged as a java war file ready to serve. The war includes afilter that sets the Cache-Control header to encourage browser caching.

  • cometd artifacts for java API and cometd example war

However, if you are a "from first principals" type, then to checkout and build dojo is now as simple as:

svn co http://svn.dojotoolkit.org/src/view/anon/all/trunk dojo
cd dojo/util/maven
mvn

This will build the standard dojo release and package it as a zip, atar.gz and tar.gz2 and make them available in your local repository.The groupId is org.dojotoolkit and the artifactId is dojo. The following incantation of the maven dependency plugin will download and unpack these artifacts into your maven project:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack dojo</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo</artifactId>
<version>${project.version}</version>
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/dojo</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

Along with the build of the dojo release artifacts, dojo is also packaged as a war file with groupId org.dojotoolkit and artifactId dojo-war.The war produced by this can be directly deployed and used by other webapplications on the same server (there is no requirement for js to beserved from the same war as your application). Alternately, this warcan be used as an overlay by the maven war plugin and merged with yourown war project:

<project xmlns="...">
<modelVersion>4.0.0</modelVersion>
<groupId>vom.acme</groupId>
<artifactId>myproject</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay></overlay>
<overlay>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo-war</artifactId>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo-war</artifactId>
<version>1.2-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

Currently only snapshot releases have been deployed to the repository(1.2-SNAPSHOT). Once we have some feedback that this is working OK, Iwill deploy a retrospective dojo 1.1.1 release and organize for that tobe mirrored to the central maven repositories.   Until that time, youcan access the dojo repositories directly with the followingincantation in your pom.xml:

 Currently only snapshot releases have been deployed to the repository (1.2-SNAPSHOT). Once we have some feedback that this is working OK, I will deploy a retrospective dojo 1.1.1 release and organize for that to be mirrored to the central maven repositories.   Until that time, you can access the dojo repositories directly with the following incantation in your pom.xml:

<repositories>
<repository>
<id>dojo</id>
<name>Dojo Maven2 Repository</name>
<url>http://download.dojotoolkit.org/maven2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>dojoSnapshots</id>
<name>Dojo Maven2 Snapshot Repository</name>
<url>http://download.dojotoolkit.org/maven2-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<layout>default</layout>
</repository>
</repositories>

I am now using these artifacts to better mavenize the cometd projectand it's examples. Feedback on the repositories and the packaging ismost welcome.

References
Published at DZone with permission of its author, Greg Wilkins. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)