Random Maven Tips

Alex Miller's maven tip file.

Turn on Compiler Warnings

By default, Maven hides compiler warnings. Add some config to expose them.


<plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
      <source>${jdk.compiler.version}</source>
      <target>${jdk.compiler.version}</target>
      <compilerArgument>-Xlint:all</compilerArgument>
      <showWarnings>true</showWarnings>
      <showDeprecation>true</showDeprecation>
   </configuration>
</plugin>

Editting the Version in Multiple POMS

So, you got a multi module project and you need to edit the version in a whole bunch of poms. A real pain.
sed to the rescue.

sed -i "s/0.23-SNAPSHOT/0.24-SNAPSHOT/g" `find . -name pom.xml`

Now, just deploy...

mvn clean install deploy:deploy -DperformRelease=true

Adding JMS to the Maven Repository

Much like mail and JTA, Sun's license on the JMS api keeps it out of the public maven repositories. Weird to be so restrictive about little more than a bunch of interfaces. I'd expect it on real code. Anyways....

Get the JMS package from http://java.sun.com/products/jms/docs.html Open the zip file and find 2 jars in the lib sub-directory. Use the following two commands to upload them.

mvn deploy:deploy-file -Dfile=jms.jar     \
   -DgroupId=jms                          \
   -DartifactId=jms -Dversion=1.1         \
   -Dpackaging=jar -DrepositoryId=my.repo \
   -Durl=http://nexus.myserver.com/nexus/content/repositories/my.repo
mvn deploy:deploy-file -Dfile=javax.jms.jar \
   -DgroupId=javax.jms                      \
   -DartifactId=jms -Dversion=1.1           \
   -Dpackaging=jar -DrepositoryId=my.repo   \
   -Durl=http://nexus.myserver.com/nexus/content/repositories/my.repo

Your pom can now use the JMS api's whoohoo!

Adding JTA to a Maven Repository

For my case, I wanted to add the JTA to an in-house Nexus Repository. The package doesn't appear on the public repositories because of Sun's License.

To do this, I downloaded the api classes from sun: http://java.sun.com/products/jta

They provide a zip file instead of a jar (for some unknown reason). So, first, I unzipped the file and repackaged as a jar. To deploy to the repository, I just used the following command:

mvn deploy:deploy-file -Dfile=jta.jar     \
   -DgroupId=javax.transaction            \
   -DartifactId=jta -Dversion=1.1         \
   -Dpackaging=jar -DrepositoryId=my.repo \
   -Durl=http://nexus.myserver.com/nexus/content/repositories/my.repo

Note: the line above was for verison 1.1.
Be sure to edit the verison number if using a different version.

Now, developers, testers, and builders don't need to worry about the process of downloading and installing the package to their local repositories.

maven-pmd-plugin and Memory

Use care when configuring this plugin with <includeTests>false</includeTests>. Because many unit tests declare that they throw java.lang.Exception, you may find the site task runs out of memory.

Soultion, try to get the violations to a reasonable number first. My TODO, try to figure out how to get PMD to filter out those types of violations in Maven...



Sponsors:

About willCode4Beer