My favorites | Sign in
Project Logo
                
Search
for
Updated Oct 31, 2009 by mathieu.carbou
Labels: Featured, Phase-Implementation, Phase-Deploy
HowTo  
How to use maven-license-plugin

maven-license-plugin configuration reference

See the maven-license-plugin configuration reference wiki page to have for information about all the possible configuration options of this plugin !

STEP 1: Set Maven 2 repository

maven-license-plugin is available in Maven Central Repo at http://repo1.maven.org/maven2/com/mycila/maven-license-plugin/

to get the really latest releases and snapshots

Since it can take some weeks before releases are uploaded in the central repo by the maven team, i provide a maven repository that you can use to get the plugin.

Add in your POM or settings.xml file the plugin repository mc-repo here. See explanations at http://code.google.com/p/mc-repo/wiki/HowToUse.

You should only need to add this:

<pluginRepository>
    <id>mc-release</id>
    <name>Local Maven repository of releases</name>
    <url>http://mc-repo.googlecode.com/svn/maven2/releases</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <releases>
        <enabled>true</enabled>
    </releases>
</pluginRepository>

and for snapshots

<pluginRepository>
    <id>mc-release</id>
    <name>Local Maven repository of releases</name>
    <url>http://mc-repo.googlecode.com/svn/maven2/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
    <releases>
        <enabled>false</enabled>
    </releases>
</pluginRepository>

STEP 2: Create a header file

The plugin needs that you put a file on your project that contain the header, license or whatever text you want to see on the top of your source files. In the examples below, the file header.txt has the following content:

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.

You can also provide for the header any valid URL or a resource from the classpath

Be careful about line end !

On Windows, lines end with CRLF (\r\n) whereas on Unix they end with LF (\n). If you apply a header file saved in Windows format to your files developed on Unix, you will end up with files having line ends like in Unix, except for the header part: you will have \r\n. The side effect is that in some Unix editors, you could see ^M characters at line ends for the header part.

The solution is very simple: you just have to convert your header with dos2unix. You can also convert all your project files like this:

for i in `find src -type f | grep -v .svn | grep -v java`; do dos2unix $i; done
- Thanks to Erik Drolshammer's report

STEP 3: Check for missing headers (goal: check)

To launch a check, simply add the plugin to your POM and issue:

mvn license:check -Dyear=2008 -Demail=myemail@company.com

<build>
    <plugins>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <configuration>
                <header>src/etc/header.txt</header>
            </configuration>
        </plugin>
    </plugins>
</build>

You can also automatically bind the check to the verify phase if you want a build to fail when missing headers are found. You just have to include the following declaration to check for missing headers, and then issue:

mvn verify -Dyear=2008 -Demail=myemail@company.com

<build>
    <plugins>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <configuration>
                <header>src/etc/header.txt</header>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

If you want to bind to another phase, i.e. the test phase, you just have to declare the phase in the execution tag like this:

<build>
    <plugins>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <configuration>
                <header>src/etc/header.txt</header>
            </configuration>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

With this, you will then check the headers after the tests by doing mvn test -Dyear=2008 -Demail=myemail@company.com

Note: The properties in the header and in the command line are optional. If you prefer, you can set directly the values in the header and not use properties. Also, you would prefer configuring the plugin for your needs to set properties in the maven POM. See the maven-license-plugin configuration guide to see all the possibilities of this plugin.

STEP 4: Add missing headers (goal: format)

This goal enables you to add or update existing license headers to put the one in the header file you have specified.

To launch it: mvn license:format -Dyear=2008 -Demail=myemail@company.com (having the configuration below)

<build>
    <plugins>
        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <configuration>
                <header>src/etc/header.txt</header>
            </configuration>
        </plugin>
    </plugins>
</build>

Comment by altumano, Feb 26, 2008

INFO? Ignoring available plugin update: 1.0.4 as it requires Maven version 2.0.8

Comment by kaz.balos, Feb 27, 2008

What to do in order to have normal comment (slash plus one star) instead of javadoc comment (slash plus two stars)?

Comment by altumano, Mar 04, 2008

Can it run on Maven versions earlier that 2.0.8 ?

Comment by m...@jtheuer.de, Apr 01, 2008

Is it possible to use the initial svn comitter and (all/the last) commiter? Is it possible to get the full name from the system instead of the userid?

It is a great plugin, but I don't know how to use it with multiple commiters together because everytime I overwrite the other's headers...

Comment by mathieu.carbou, Jun 19, 2008

Hi,

For userid from SVN, it is not posible. The plugin has been done so that license files are the same for all files or at least the same for some sets of file id you use maven profiles.

For Maven 2.0.8 version, yes it should be possible to run in fewer maven versions. It's an issue in the current pom... Could you please open a defect for this in the issue tracker ? Thank you !

Comment by valerio.schiavoni, Dec 09, 2008

For multi-module projects, does each module has to provide the same header.txt in the same location? The ideal would be to put it only at the root-project level...is it already like that ?

Comment by mathieu.carbou, Dec 09, 2008

Yes you have an example of that in my other project at http://code.google.com/p/mycila/. Mycila Testing is build this way. You have in your parent POM to put <inherited>false</inherited> on the plugin. Example here: http://code.google.com/p/mycila/source/browse/mycila-testing/trunk/pom.xml

Comment by mathieu.carbou, Dec 09, 2008

... and do not forget the aggregate option ;)

Comment by withinsea, Dec 28, 2008

Hi, have you got plan to support ant tasks? This plugin is too powerful....

Comment by MimilOwns, Dec 29, 2008

Hi, yes look at issue 37.

Comment by marcel.schepers, Jan 06, 2009

Is there a way to treat a file with an unknown extenstion as a file with a known extension? For example, treat WSDL files as XML files.

Comment by MimilOwns, Jan 06, 2009

Hi, yes. Have a look at the following page: http://code.google.com/p/maven-license-plugin/wiki/SupportedFormats

Comment by ptolemy428, Jan 29, 2009

Just had a try with this plugin. worked like a charm. Great work, Thanks guys!

How can you not love maven!

Comment by joe.butler, Mar 02, 2009

I maintain numerous multi-module projects that all need the same license.txt. These projects all inherit from a project parent POM. I would rather not define the license.txt at the parent level of each multi-level project, but at the higher level project parent POM, because if the license changes on me - I dont want to go into each multi-module project and update the same text. Is there a way to do this? If I define the plugin at the project parent level, each child project is looking for the license.txt within its own project.

Comment by mathieu.carbou, Mar 02, 2009

Hi,

The header location can be an absolute path, relative path, classpath or URL. The classpath is serached from the plugin classpath and the project classpath. You can have a per module management or global management. See this issue for more details: http://code.google.com/p/maven-license-plugin/issues/detail?id=52

Thank you !

Comment by joe.butler, Mar 02, 2009

I get it! I had my project pom reference an absolute path, and now child projects all know where to go to get their header. Thanks again for the plugin and the advice.

Comment by joe.butler, Mar 03, 2009

Just another following up, with a different approach. I created a separate license maven project, and exported the resource bundle containing the license.txt using the maven-remote-resources-plugin. The parent project POM then processes that license bundle with maven-remote-resource-plugin, which makes it available to any dependent project. All child projects now have their licenses and no updates to their own individual POMs! For my development environment, this approach works out much nicer than an absolute path or URL. Thanks again.

Comment by salbanese0080, May 02, 2009

Plugin is great, would be amazing if it could be used to inject svn keywords without overwriting them later

Comment by aheritier, Aug 17, 2009

This plugin is really great. Perhaps you could propose to move it to mojo.codehaus.org You'll have a native rsync for your releases, and you could receive the help of others committers

Comment by mathieu.carbou, Aug 17, 2009

Hi,

There is also a sync from Google Code to Maven Central Repo, i use it for my projects in com.mycila groupIds.

The fact is that i currently really run out of time and i have no help at all ;) I've already planed with Jason (Maven creator) to move this plugin under the Sonatype infrastructure. I just need to migrate the source and documentation.

Mat'

Comment by Andrei.Pozolotin, Sep 05, 2009

Great project; Thank you!


Sign in to add a comment
Hosted by Google Code