In my case I had a Map full of complex objects. Each of my complex objects held an arraylist of photo albums. As I was going to be iterating over the map later on I wanted to be able to get the elements out of the map ordered by the number of photoalbums in each element value - in descending order:

Groovy to the rescue with the spaceship operator (<=>) and a simple one liner:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target><compilerId>groovy-eclipse-compiler</compilerId> <verbose>false</verbose> </configuration><dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.6.0-01</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> <version>1.8.6-01</version> </dependency> </dependencies> </plugin>At that's basically it. If you are working on a Spring MVC project like I am, you can now create .groovy files in src/main/java or src/main/groovy. In addition you can also annotate them with @Service etc and @Autowire them into other Java or Groovy classes.One problem I did have was autowiring a groovy bean that was annotated with @Transactional into another. It turns out the probject was because the class did not have an interface and this causes proxy problems for Spring. The following change to the bean solved the problem: