Yes, you can do that in Maven

I’ve heard too many people complaining that they can’t do something in Maven, or that it’s too hard. There are generally three categories people complain about:

  • 1 - Executing arbitrary code.
  • 2 - Multiple deploys/packages from one pom file.
  • 3 - Too much XML.

Well, there’s not much we can do about #3 (although there have been some efforts to use other formats), but the other two are very possible.

#1: Executing arbitrary code

You can execute groovy code from maven, you execute Ant build files, you can execute Scala from maven, and you can even write your own plugins in groovy if you’d like.

#2: Multiple jars/deploys

There are many way to do this which have been covered. Mainly, I would use the multiple executions. In other words, just put multiple executions in your configuration of the jar- deploy- whatever- plugin! However, Sonatype recommends you use multiple modules instead: “We strongly recommend that you not configure a Maven project to create two separate JARs from a single project.  It violates one of the most important core concepts of Maven: modularity.”

I’m not saying Maven is perfect. If you don’t like XML or the declarative syntax, that’s a perfectly valid opinion - just don’t say it can’t do things it so clearly can.

Tags: maven java