My favorites | Sign in
Project Logo
                
Search
for
Configuration  
maven-license-plugin configuration reference guide

Plugin info on maven website

See http://mathieu.carbou.free.fr/p/maven-license-plugin/plugin-info.html

Available goals

  • license:check: verify if some files miss license header
  • license:format: add the license header when missing. If a header is existing, it is updated to the new one.
  • license:remove: remove existing license header

maven-license-plugin configuration options

A lot of configuration options can be passed to the command line as parameters to override those in the POM. This is described below.

Here is an example of a full declaration of the plugin with all its options

<build>
    <plugins>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <configuration>
                <basedir>${basedir}</basedir>
                <header>${basedir}/src/etc/header.txt</header>
                <quiet>false</quiet>
                <failIfMissing>true</failIfMissing>
                <aggregate>false</aggregate>
                <includes>
                    <include>src/**</include>
                    <include>**/test/**</include>
                </includes>
                <excludes>
                    <exclude>target/**</exclude>
                    <exclude>.clover/**</exclude>
                </excludes>
                <useDefaultExcludes>true</useDefaultExcludes>
                <mapping>
                    <jwc>XML_STYLE</jwc>
                    <application>XML_STYLE</application>
                    <myFileExtension>JAVADOC_STYLE</myFileExtension>
                </mapping>
                <useDefaultMapping>true</useDefaultMapping>
                <properties>
                    <year>${project.inceptionYear}</year>
                    <email>my@email.com</email>
                </properties>
                <encoding>UTF-8</encoding>
                <headerDefinitions>
                    <headerDefinition>def1.xml</headerDefinition>
                    <headerDefinition>def2.xml</headerDefinition>
                </headerDefinitions>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The table below shows all the available options you can use in the configure section of the plugin. A lot of are also available from the command-line. To use them, simply launch your maven command with a property like -Dproperty=value (i.e. mvn license:check -Dlicense.header=src/etc/header.txt)

option status default command-line description
basedir optional ${basedir} -Dlicense.basedir=folder Specify the folder as the base directory for the search
header required -Dlicense.header=path to header file Location of the header. It can be a relative path, absolute path, classpath resource, any URL. The plugin first check if the name specified is a relative file, then an absolute file, then in the claspath. If not found, it tries to construct a URL from the location. An example of the content for Apache 2 license is here
quiet optional false -Dlicense.quiet=true If you do not want to see the list of file having a missing header, you can add the quiet flag that will shorten the output
failIfMissing optional true -Dlicense.failIfMissing=false You can set this flag to false if you do not want the build to fail when some headers are missing. This flag is only available with goal check
aggregate optional false -Dlicense.aggregate=false You can set this flag to true if you want to check the headers for all modules of your project. Only used for multi-modules projects, to check for example the header licenses in the parent pom for all sub modules
includes optional ** (all) By default all files are included. You can reduce the set of included files by adding include tags with patterns
excludes optional empty You can exclude some files in your project from the check by specifying a list of pattern
useDefaultExcludes optional true -Dlicense.useDefaultExcludes=false Specify if you want to use default exclusions besides the files you have excluded. Default exclusion removes CVS and SVN folders, IDE descriptors and so on. The default value of these exclusions is shown below this table
mapping optional empty This section is very useful when you want to customize the supported extensions. Is your project is using file extensions not supported by default by this plugin, you can add a mapping to attach the extension to an existing type of comment. The tag name is the new extension name to support, and the value is the name of the comment type to use. The list of the comment type names is listed on the page here and below the table
useDefaultMapping optional true -Dlicense.useDefaultMapping=false Specify if you want to use or not the default extension mapping for supported file extensions. If you do not use it, you will have to add mappings manual for each extension you want to use. See more details below
properties optional empty You can set here some properties that you want to use when reading the header file. You can use in your header file some properties like ${year}, ${owner} or whatever you want for the name. They will be replaced when the header file is read by those you specified in the command line, in the POM and in system environment.
encoding optional ${file.encoding} -Dlicense.encoding=encoding Specify the encoding of your files. Default to current system encoding
headerDefinitions optional empty Enables to redefine the header detection patterns and the header templates
dryRun optional false -Dlicense.dryRun=true If dryRun is enabled, calls to license:format and license:remove will not overwrite the existing file but instead write the result to a new file with the same name but ending with .licensed
keywords optional copyright Specify the list of keywords to use to detect a header. A header must include all keywords to be valid. By default, the word 'copyright' is used. Detection is done case insensitive.

Default excludes

Patterns that are excluded by default when using useDefaultExcludes (default to true):

"**/target/**", "**/test-output/**", "**/release.properties",  "**/pom.xml",
"**/cobertura.ser", "**/.clover/**",
"**/.classpath", "**/.project", "**/.settings/**",
"**/*.iml", "**/*.ipr", "**/*.iws",
"**/*.jpg", "**/*.png", "**/*.gif", "**/*.ico",
"**/*.class", "**/MANIFEST.MF"

Supported comment types

There are all described in the Home page. The list contains:

java, xml, properties, apt, batch, text, sql, jsp, ftl, ...

Default mappings

The default mapping is built using the file extension and the style of comment to use. By default, the mapping between supported extensions and comment type contains the supported extensions here. You can customize the default mapping by providing your own one:

<mapping>
    <java>JAVADOC_STYLE</java>
    <groovy>JAVADOC_STYLE</groovy>
    <js>JAVADOC_STYLE</js>
    <css>JAVADOC_STYLE</css>
    <xml>XML_STYLE</xml>
    <dtd>XML_STYLE</dtd>
    <xsd>XML_STYLE</xsd>
    <html>XML_STYLE</html>
    <htm>XML_STYLE</htm>
    <xsl>XML_STYLE</xsl>
    <fml>XML_STYLE</fml>
    <apt>DOUBLETILDE_STYLE</apt>
    <properties>SCRIPT_STYLE</properties>
    <sh>SCRIPT_STYLE</sh>
    <txt>TEXT</txt>
    <bat>BATCH</bat>
    <cmd>BATCH</cmd>
    <sql>DOUBLEDASHES_STYLE</sql>
    <jsp>DYNASCRIPT_STYLE</jsp>
    <ftl>FTL</ftl>
    <xhtml>XML_STYLE</xhtml>
    <vm>SHARPSTAR_STYLE</vm>
    <jspx>XML_STYLE</jspx>
</mapping>

Variable replacement

If you have a header that contains variable like this one:

Copyright (C) ${year} ${user.name} <${email}>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

The plugin will try to replace them using the properties supplied in the command line, then those supplied in the POM, and then those from the system environment.

To test, you can launch the check goal in debug mode like this:

mvn -X license:check -Dyear=2010

Outputs for me:

Copyright (C) 2010 kha <my@email.com>

Notice that the year 2008 specified in the POM above has been overridden by the java property. And since the user.name is already a java system property, you don't need to specify it.

Debugging, controlling the output

The plugin let you control the output by the license.quiet property.

But to see if the plugin is working well, if your header is parsed correctly with properties, you may need to activate the Maven debug flag -X to see the plugin debug output.

Example: mvn -X license:check

Changing header style definitions

In maven-license-plugin, each header style is defined by patterns to detect it and also strings to insert it correctly in files. If we take for example the Javadoc style header definition. It is defined as follow:

<?xml version="1.0" encoding="ISO-8859-1"?>
<additionalHeaders>
    <javadoc_style>
        <firstLine>/**</firstLine>
        <beforeEachLine> * </beforeEachLine>
        <endLine> */</endLine>
        <!--skipLine></skipLine-->
        <firstLineDetectionPattern>(\s|\t)*/\*.*$</firstLineDetectionPattern>
        <lastLineDetectionPattern>.*\*/(\s|\t)*$</lastLineDetectionPattern>
        <allowBlankLines>false</allowBlankLines>
        <isMultiline>true</isMultiline>
    </javadoc_style>
</additionalHeaders>

And for XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<additionalHeaders>
    <javadoc_style>
        <firstLine><![CDATA[<!--\n]]></firstLine>
        <beforeEachLine>    </beforeEachLine>
        <endLine><![CDATA[-->]]></endLine>
        <skipLine><![CDATA[^<\?xml.*>$]]></skipLine>
        <firstLineDetectionPattern><![CDATA[(\s|\t)*<!--.*$]]></firstLineDetectionPattern>
        <lastLineDetectionPattern><![CDATA[.*-->(\s|\t)*$]]></lastLineDetectionPattern>
        <allowBlankLines>false</allowBlankLines>
        <isMultiline>true</isMultiline>
    </javadoc_style>
</additionalHeaders>

With the headerDefinitions option, you can redefine existing header styles and also add some if we do not support the styles you want yet. You just have to provide a list of headerDefinition containing a resource name. Like the header, the resource is searched on the file system, in the classpath of the project, the plugin and also as a URL.

See Advanced Headers configuration for more information

Working with multi-module projects

here is an example of configuration you can have in a parent pom, when working in a multimodule project:

<plugin>
    <inherited>false</inherited>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <header>${basedir}/etc/header.txt</header>
        <failIfMissing>true</failIfMissing>
        <aggregate>true</aggregate>
        <properties>
            <owner>Mathieu Carbou</owner>
            <year>${project.inceptionYear}</year>
            <email>mathieu.carbou@gmail.com</email>
        </properties>
        <excludes>
            <exclude>LICENSE.txt</exclude>
            <exclude>**/src/test/resources/**</exclude>
            <exclude>**/src/test/data/**</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>check-headers</id>
            <phase>verify</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Comment by mhoebeke, Apr 07, 2008

Great plug-in. It saved me a whole lot of time. A small detail about the default excludes. When working with nested modules, it would be soooo much easier to have /.project, /.settings/ and /.classpath.

Comment by two...@bluestemsoftware.com, May 03, 2008

Awesome. 1000 + source files. Three different licenses. No problem. Thanks.

Comment by jmherzet, May 04, 2008

Good job, very usefull Thanks a lot for saved time JMH

Comment by vidocq, May 06, 2008

In the first plugin configuration example you have the "header" tag opened but closed by a mismatched "File" tag ;-)

Comment by mathieu.carbou, Jun 19, 2008

Thank you ! It's fixed ;)

Comment by nguyen.anhquan, Nov 24, 2008

Great! It saves me a lot of time.

Thanks a lot, Mathieu

Comment by jameslorenzen, Jan 07, 2009

A dryRun option on the format would be nice too. See the maven-release-plugin. It would just spit out all the files license:format would modify.

Comment by n...@ebbutt.net, Jan 23, 2009

Mathieu, thanks a lot for this great plugin Worked out of the box for me and took about 5 mins to get going, an instant time saving. A lot of kudos for this.

Comment by edward.i...@gmail.com, Jul 01, 2009

The "Default excludes" section does not reflect the actual default excludes in the latest release. Maybe it would be helpful for others browsing these docs.

Great plugin. Thanks.

Comment by Andrei.Pozolotin, Sep 07, 2009

Hi; I have log4j.properties file that gets header added every time I run "format"; file just keeps growing; what am I missing? Thank you.

Comment by mathieu.carbou, Sep 07, 2009

Hi,

There is an issue in the latest version concerning certain types of formatting. See here for details (http://code.google.com/p/maven-license-plugin/issues/list). If you really need them, please use the 1.3.x versions. Otherwise you can simply exclude the .properties files.

Mathieu.

Comment by Andrei.Pozolotin, Sep 07, 2009

Mathieu, hi; thanks for getting back; I will exclude the .properties files for now; cheers.


Sign in to add a comment
Hosted by Google Code