|
Configuration
maven-license-plugin configuration reference guide
Plugin info on maven websiteSee http://mathieu.carbou.free.fr/p/maven-license-plugin/plugin-info.html Available goals
maven-license-plugin configuration optionsA 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)
Default excludesPatterns 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 typesThere are all described in the Home page. The list contains: java, xml, properties, apt, batch, text, sql, jsp, ftl, ... Default mappingsThe 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 replacementIf 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 outputThe 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 definitionsIn 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 projectshere 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>
|
Sign in to add a comment
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.
Awesome. 1000 + source files. Three different licenses. No problem. Thanks.
Good job, very usefull Thanks a lot for saved time JMH
In the first plugin configuration example you have the "header" tag opened but closed by a mismatched "File" tag ;-)
Thank you ! It's fixed ;)
Great! It saves me a lot of time.
Thanks a lot, Mathieu
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.
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.
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.
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.
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.
Mathieu, hi; thanks for getting back; I will exclude the .properties files for now; cheers.