Fork me on GitHub

Update File Header Examples

The update-file-header goal can be configured this way:

  • licenseName : it is the name of the license to add on file header. It is mandatory,
  • roots : it is a list of the main directories from which we apply the license on files. The default roots is src, target/generated-sources, target/processed-source,
  • includes : List of files to include, given by a regexp (for example: *Dao.java). The default include is **/*,
  • excludes: List of files to exclude, given by a regexp (for example: *Test.java). No files are excludes by default.
  • extraExtensions: Dictionary of extensions to map to existing comment style.
  • extraFiles: Dictionary of files to existing comment style.
  • customize description section: Define a template to change the description section of a file header.

To see all extensions accepted run the comment-style-list goal.

[INFO] --- license-maven-plugin:2.4.0:comment-style-list (default-cli) @ license-maven-plugin ---
[INFO] List of available comment styles:

  - apt        : header transformer with apt comment style            , extensions : [apt]
  - ftl        : header transformer with free marker comment style    , extensions : [ftl]
  - java       : header transformer with java comment style           , extensions : [java, groovy, css, cs, as, aj, c, h, cpp, js, json]
  - jsp        : header transformer with jsp comment style            , extensions : [jsp, jspx]
  - php        : header transformer with php comment style            , extensions : [php]
  - properties : header transformer with properties file comment style, extensions : [properties, sh, py, rb, pl, pm]
  - rst        : header transformer with rst comment style            , extensions : [rst]
  - mysql      : header transformer with mysql comment style          , extensions : [mysql]
  - sql        : header transformer with sql comment style            , extensions : [sql]
  - xml        : header transformer with xml comment style            , extensions : [pom, xml, xhtml, mxlm, dtd, fml, xsl, html, htm, jaxx, kml, gsp, tml]

Root Directories

By default, All the files in src, target/generated-sources, target/processed-source are treated. This could be changed with the property roots. The roots property is a list of base directories from which the update-file-header will be applied.

Example

Given a pom with this plugin configuration:

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <verbose>false</verbose>
          <addSvnKeyWords>true</addSvnKeyWords>
        </configuration>
        <executions>
          <execution>
            <id>first</id>
            <goals>
              <goal>update-file-header</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
              <licenseName>gpl_v3</licenseName>
              <roots>
                <root>src/main/java</root>
                <root>src/test</root>
              </roots>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  Considering we have the following tree:
  src/main/java
  src/main/resources
  src/test/java
  src/test/resources

Only files from src/main/java, src/test/java and src/test/resources will be treated.

Includes

By default, all the files from the roots and with the adequate extension are treated. With the list parameters includes, we can specify with more precision which files we want to deal.

Example

Given a pom with this plugin configuration:

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <verbose>false</verbose>
          <addSvnKeyWords>true</addSvnKeyWords>
        </configuration>
        <executions>
          <execution>
            <id>first</id>
            <goals>
              <goal>update-file-header</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
              <licenseName>gpl_v3</licenseName>
              <includes>
                <include>*Dao.java</include>
                <include>*Bean.java</include>
                <include>.*entities.*.xml</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

The update-file-header will be done only on java files (from "src") ending with "Dao" and "Bean" and on xml files containing "entities" in their file name.

Excludes

The excludes parameter allows to ignore some file in the update-file-header process.

Example

Given a pom with this plugin configuration:

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <verbose>false</verbose>
          <addSvnKeyWords>true</addSvnKeyWords>
        </configuration>
        <executions>
          <execution>
            <id>first</id>
            <goals>
              <goal>update-file-header</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
              <licenseName>gpl_v3</licenseName>
              <excludes>
                <exclude>*.png</exclude>
                <exclude>*.txt</exclude>
                <exclude>*Test.java</exclude>
              </excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

The java files ending with "Test", the png files and the txt files will be ignored by the update-file-header goal.

ExtraExtensions

To use more extensions, add a mapped parameter where keys are extensions and values are the comment style type to use.

Example

Given a pom with this plugin configuration:

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <extraExtensions>
            <myProprietaryExtension>java</myProprietaryExtension>
          </extraExtensions>
        </configuration>
      </plugin>
    </plugins>

Files with extension myProprietaryExtension will be treated as java files (says using the comment style named java).

ExtraFiles

To match exact files, add a mapped parameter where keys are name of files and values are the comment style type to use.

Example

Given a pom with this plugin configuration:

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <extraFiles>
            <DockerFile>properties</DockerFile>
          </extraFiles>
        </configuration>
      </plugin>
    </plugins>

Files named DockerFile will be treated as properties files (says using the comment style named properties).

Customize the description section

Since version 1.1, it is possible to customize the description section of a file header using a freemarker template.

Use your own template by overriding the descriptionTemplate parameter.

In the template you can use these variables:

Example

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <descriptionTemplate>${basedir}/src/license/myDescriptionTemplate.ftl</descriptionTemplate>
        </configuration>
      </plugin>
    </plugins>

With this freemarker template located in ${basedir}/src/license/myDescriptionTemplate.ftl:

<#-- To render the description of a license file header.
 Available context :
 - project the maven project
 - addSvnKeyWords
 - organizationName
 - projectName
 - inceptionYear
 - file current file to treat
-->
${file.name} - ${projectName} - ${organizationName} - ${inceptionYear}
org.codehaus.mojo-license-maven-plugin-2.4.0
$Id$
$HeadURL$