Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

2011-10-13

Guidelines for Multi-moduled Maven Project []

Moved to the page http://3rdstage.wikia.com/wiki/Tips_on_Maven in my wiki as of 23th Jul. 2012.

Guidelines for Multi-moduled Maven Project

Separate parent project from container project.
Define properties in the parent POM file as possible.
Define the following properties explicitly for clearness and control.
  • Encoding related properties whose default value are dependent on platform.
    • project.build.sourceEncoding
    • project.reporting.outputEncoding
  • Properties to skip situationally unnecessary long running goals.
    • skipTests
    • maven.javadoc.skip
    • maven.deploy.skip
    • checkstyle.skip
  • Properties to run maven more stable way.
  • Paths for executable programs external to Maven
    • graphviz.home
Define all plugins in the <pluginManagement> element of parent POM file.
  • Don't specify version to plugin definitions in child POM files.
Define repositories in the parent POM file as possible.
Define plugins to analyze or diagnose the sources or resources of the project as a reporting plugin as possible.
Start values for path with ${project.basedir}, ${project.build.directory}, ${project.build.outputDirectory} or so on
  • When just specifying relative path such as 'target/classes', the result directory could be different if you build the project from the enclosing project in multi-module case.
  • If you specify the path with leading ${project.build.directory}, the resulting directory always would be one that is calculated with the current POM's project.
Use resources in target/classes not in src/main/resources, considering resource filtering.

Sample of Parent POM

This is the real sample of parent POM I am using.

2009-09-05

Tips on Maven []

Moved to the pages http://3rdstage.wikia.com/wiki/Readings_on_Maven and http://3rdstage.wikia.com/wiki/Tips_on_Maven in my wiki as of 23th Jul. 2012.

Overview

Readings : references, tutorials and articles

Sonatype books
Maven assemblies
Maven snapshot repositories
Deployment process and security
Site process
Release process
Property and Interpolation
misc

Referencing Maven project properties of List type

//@todo

This syntax works within pom.xml and Ant build files using Maven Ant plugin. But this doesn't working with resource filtering of Maven. I can't find any explain or reason for this. Is it a bug?


   ...
   <artifact:pom id="this-pom" file="${basedir}/pom.xml"/>
   <xsddoc out="${this-pom.reporting.outputDirectory}/xsddocs"
      verbose="true">
      <fileset dir="${this-pom.build.resources[0].directory}" 
         includes="**/*.xsd"/>
   </xsddoc>
   ...

Build Lifecycle, Build Phase, Plugin and Goal

Simple tips and troubleshooting

  • The value of Maven property "project.build.directory" in normal case is ${basedir}/target. You can confirm this using the following command line : "mvn help:evaluate -Dexpression=project.build.directory".
  • Solving "org.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60" exception when running site:site goal
    Simply add a dependency on a newer version(eg. 3.8) of icu4j
  • Solving "[ERROR] Unable to determine if resource ... exists in .." error.
    Or just add <dependency.locations.enabled>false</dependency.locations.enabled> into the <properties> element of POM file.
  • Using <addClasspath> when you have no dependencies fails with FileNotFoundException
    Configuring to add classpath to MANIFEST file can cause unreasonable exception when running maven-jar-plugin without compile or run-time scope dependency. If you run package with -X option, you can identify exception whose stack goes like this.

Dependency on local library not in Maven repository and with no POM file

Sometimes your project may have dependency on a JAR file that is not registered to any of Maven repositories and so have no it's own POM file. In this case, you can use <systemPath> element to specify your module's dependency on it.

Note that systemPath could be specified only with system scope. You should specify groupId, artifactId, and version 'cause they are mandatory but you can specify any value and don't need pom file.

Escaping expression interpolation

It may necessary not to interpolate Maven expression in resources. In other words, you just want to leave ${some-property} as it is. For this, you can specify the escape string with escapeString parameter of maven-resource-plugin. You can also define maven.resources.escapeString property in your POM file.

For more refer this page : http://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#escapeString

Client configuration

The location of client configuration files for subversion is dependent on operating system.

  • Windows : %USERPROFILE%\Application Data\Subversion\config
  • Linux : ~/.subversion/config

Configurable options are described here : http://svnbook.red-bean.com/en/1.5/svn.advanced.confarea.html#svn.advanced.confarea.opts.config

Working with Subversion working copy in format of ver. 1.7

The default configuration of Maven release plugin(maven-release-plugin) up to ver. 2.2.2 or Maven scm plugin(maven-scm-plugin) up to ver. 1.6 can't work correctly with Subversion working copy in format of ver. 1.7.
To solve this problem, you should override the configuration of release plugin or scm plugin to use maven-scm-provider-svnjava and svnkit 1.7.

For now, svnkit 1.7 has no release and is in snapshot version.

If you let the plugins use svnkit 1.3.x which is default setting as of now, you would meet the exceptions like the following.

For more, refer the followings,

2009-03-15

Notable Maven Repositories, Plug-ins and Skins []

Moved to the page http://3rdstage.wikia.com/wiki/Notable_Maven_Repositories,_Plug-ins_and_Skins in my wiki as of 23th Jul. 2012.

Maven Repositories

Maven Plug-ins

Code analysis tools plug-in
Collaboration tools plug-in
Source configuration management tools plug-in
Non-java build plug-in

Maven Skins