Skip to content
Manage license headers in your source files
Branch: master
Clone or download
mathieucarbou Merge pull request #149 from mycila/issue/121
Close #121: Added new style: SCALA_STYLE
Latest commit bdef2dc Feb 6, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.

The following documentation is not up to date.

Please help if you want to contribute!

Upcoming release

Lastest releases (note that it may take up to 1-2 days to be in Maven Central repository):

Table of Contents

Maven License Plugin (the Official and Original one)

Basically, when you are developing a project either in open source or in a company, you often need to add at the top of your source files a license to protect your work. I didn't find any maven plugin on Internet to help you maintain these license headers. By maintaining, i mean checking if the header is here or not, generating a report and of course having the possibility to update / reformat missing license headers.


  • check: check if header is missing in some source file
  • format: add headers if missing
  • remove: can remove existing header
  • update: update existing header with a new one
  • custom mappings: enables easy support of new file extensions
  • variable replacement: You can add some variable in your header, such as ${year}, ${owner} and they will be replaced by the corresponding values taken from the pom or system properties.



Maven Repository


Available in Maven Central Repository:


Available in OSS Repository:

Plugin declaration



Detailed Maven documentation

The detailed Maven Plugin Documentation generated for each build is available here:

WARNING: there is good chances the latest version is greater than latest documentation, if nothing has changed concerning the plugin configurations.


  • license:check: verify if some files miss license header. This goal is attached to the verify phase if declared in your pom.xml like above.
  • 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


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)

All plugin configuration options are described in the Detailed Maven documentation but here are some details.

  • useDefaultExcludes: The default exclusion list can be found here

License templates

Maven license plugin comes with the following license templates:

  • AGPL 3
  • APACHE 2
  • BSD 2, 3, 4
  • LGPL 3
  • MirOS
  • MIT
  • MPL 2

You can find those license templates with preconfigured placeholders here

Properties and placeholders

Properties which can be used as placeholder comes from:

  • Environnment variables
  • POM properties
    • project.groupId
    • project.artifactId
    • project.version
    • project.description
    • project.inceptionYear
    • project.url
  • Per-Document properties
  • Plugin configuration properties (from <properties> tag)
  • System properties

Properties are built per-document. You can provide a dependency JAR file to the plugin which contains an implementation of com.mycila.maven.plugin.license.PropertiesProvider:

public interface PropertiesProvider {
    Map<String, String> getAdditionalProperties(AbstractLicenseMojo mojo, Properties currentProperties, Document document);

You have access to the Mojo, the current built properties and the document being checked or formatted. The plugin uses the JDK ServiceLoader mechanism to find all PropertiesProvider implementations on the plugin classpath and execute them. Thus, just add the implementation class name in the file META-INF/services/com.mycila.maven.plugin.license.PropertiesProvider in your JAR file.

Supported comment types

The plugin has been designed so that it is very easy to add new supports for new sorts of comment. The plugin currently support these types of comment:

  • JAVADOC_STYLE (Java-like comments): *.java, *.groovy, *.css, *.cs, *.as, *.aj, *.c, *.h, *.cpp
     * My comment
  • JAVAPKG_STYLE (like Javadoc, but only for files that are in a Java package, skips the first line): not assigned to a file extension by default (see Java packages below for how to enable it)
    package com.example;
     * My comment
  • XML_STYLE (XML-like comments): *.pom, *.xml, *.xhtml, *.mxml, *.dtd, *.xsd, *.jspx, *.fml, *.xsl, *.html, *.htm, *.kml, *.gsp, *.tld
	    My comment
  • XML_PER_LINE (alternate XML-like comments)
	<!-- My first comment  -->
	<!-- My second comment -->

(automatically right-adjusts the closing comment)

  • DOUBLETILDE_STYLE (APT-like comments): *.apt
	~~ My comment
  • SCRIPT_STYLE (Property file or shell comments): *.properties, *.sh, *.py, *.rb, *.pl, *.pm, *.yml, *.yaml
	# My comment
  • HAML_STYLE: *.haml, *.scaml
	-# My comment
  • BATCH (Windows batch comments): *.bat, *.cmd
	@REM My comment
  • TEXT (Text like comments): *.txt
	    My comment

(4 spaces, then the lines of the header)

  • DOUBLEDASHES_STYLE (Sql like comments): *.sql, *.adb, *.ads, *.e
	-- test comment
  • DYNASCRIPT_STYLE (JSP like comments): *.jsp
  • FTL (FreeMarker like comments): *.ftl
  • FTL_ALT (FreeMarker Alternative Syntax comments)
	[#ftl ...]
  • SHARPSTAR_STYLE (Velocity templates comments): *.vm
  • SEMICOLON_STYLE (Assembler like comments): *.asm
	; comment
  • BRACESSTAR_STYLE (Delphi like comments): *.pas
	 * comment
  • APOSTROPHE_STYLE (VisualBasic like comments): *.bas
	' comment
  • EXCLAMATION_STYLE (Fortran like comments): *.f
	! comment
  • SLASHSTAR_STYLE (JavaScript like comments): *.js
	 * comment
  • DYNASCRIPT3_STYLE (Coldfusion like comments): *.cfc, *.cfm
  • PERCENT_STYLE (Teχ like comments): *.cls, *.sty, *.tex
	% comment
  • PERCENT3_STYLE (Erlang like comments): *.erl, *.hrl
	%%% comment
  • EXCLAMATION3_STYLE (Lisp like comments): *.el
	!!! comment
  • LUA (Lua like comments): *.lua
  • ASP (Asp like comments): *.asp
	' comment
  • PHP (PHP comments): *.php
	 * comment

(inserted after the <?php> tag)

  • DOUBLESLASH_STYLE (often used comments style)
	// comment

Custom mapping

The plugin enables you to add any other mapping you want.* I.e., if you are developing a Tapestry web application, you may need to add license header in .jwc files and .application files. since these files are xml files, you only need to add in your project pom the following mapping for the license-maven-plugin:


You can use composed-extensions like *.apt.vm and redefine them, but you will have to nake sure that the mapping of apt.vm is before the mapping of the vm extension. The order in the mapping section is important: extensions seen first take precedence.

Java packages

Another use case for custom mappings is when writing Java code in packages; the licence header should come after the package declaration line in this case. Simply add this to the plugin configuration:


Changing header style definitions

In license-maven-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"?>
        <beforeEachLine> * </beforeEachLine>
        <endLine> */</endLine>

And for XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
        <beforeEachLine>    </beforeEachLine>

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.

Full Example

This page will show you how you can define extended header definitions to fit your needs. The next example will define headers in a region area allowed in C# source files:

<?xml version="1.0" encoding="ISO-8859-1"?>
        <firstLine>#region LicenseEOL/**</firstLine>
        <beforeEachLine> * </beforeEachLine>
        <endLine> */EOL#endregion</endLine>
  • The EOL string will be replaced with the proper end of line depending the file format your are processing.
  • We also have defined the skipLine attribute to skip the region tags (which starts with a '#')
  • allowBlankLines allows you to define if this header style supports blank lines in it or not. In example, in XML headers, you could have blank lines after the because XML delimiters delimit a multiline block. When you work with script style comments like in Ruby, Porperties files, the # character delimit a comment for only one line. So when you create the header, for it to be uniform, you place # on each line. So allowBlankLines will be false.
  • isMultiline specifies if your header has tokens to delimit a multiline comment of if the tokens are a one-line comment. I.E.: XML style comments are multiline whereas script style comment where each line starts with # are not multiline

You now have to add this new header definition file to the plugin configuration. It is done as the following in your pom:


You now have to add the new mapping for *.cs files to use this new header definition. It is done as the following in your pom:


And it should generate headers like:

#region License
 * Copyright (C) 2008
 * 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
You can’t perform that action at this time.