How Maven handles unknown artifact types

Artifact types are specified using the type element on dependencies:

<dependency>
  <groupId>myproject</groupId>
  <artifactId>webapp</artifactId>
  <version>1.0</version>
  <type>war</type>
</dependency>

The list of artifact types defined by default can be found in the Maven documentation under Default Artifact Handlers Reference or directly in the source code. Maven plug-ins can define additional artifact types. To use a custom artifact type in a given project, the plug-in defining that artifact type must be added to the POM with extensions set to true:

<plugin>
  <groupId>org.apache.axis2</groupId>
  <artifactId>axis2-mar-maven-plugin</artifactId>
  <version>1.6.2</version>
  <extensions>true</extensions>
</plugin>

The interesting question is how Maven handles undefined artifact types. The answer is dictated by the following piece of code in DefaultArtifactHandlerManager:

handler = artifactHandlers.get( type );

if ( handler == null )
{
    handler = new DefaultArtifactHandler( type );
}

This means that Maven will not complaining about unknown artifact types. Instead it will generate artifact handlers as required. A look at DefaultArtifactHandler allows us to determine what will be the properties used by these handlers:

  • extension = type
  • packaging = type
  • classifier = null
  • language = "none"
  • addedToClasspath = false
  • includesDependencies = false