Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the license-maven-plugin

Tags:

java

maven

I would like to use the license-maven-plugin in order to be able to generate license headers for my project.

So I have the following pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.foo</groupId>
    <artifactId>bar-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Bar: Parent</name>

    <licenses>
        <license>
            <name>Apache 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>My Corp.</name>
        <url>http://www.mycorp.org/</url>
    </organization>

    <inceptionYear>2014</inceptionYear>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <license.licenseName>apache_v2</license.licenseName>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>1.6</version>

                    <configuration>
                        <verbose>false</verbose>
                        <includes>
                            <includes>**/*.java</includes>
                        </includes>
                    </configuration>

                    <executions>
                        <execution>
                            <id>generate-license-headers</id>
                            <goals>
                                <goal>update-file-header</goal>
                            </goals>
                            <phase>process-sources</phase>
                            <configuration>
                                <licenseName>Apache 2.0</licenseName>
                                <roots>
                                    <root>src/main/java</root>
                                    <root>src/test/java</root>
                                </roots>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    ...
</project>

I'm invoking the following from the command-line:

mvn license:update-file-header

This all passes, but my license header ends up looking like this:

/*
 * #%L
 * Bar: Foo
 * %%
 * Copyright (C) 2014 My Corp.
 * %%
 * 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.
 * #L%
 */

Obviously, I don't want to the #%L, %% and #L% in my license header. What do I need to set in order to get rid of those?

like image 941
carlspring Avatar asked Mar 21 '14 03:03

carlspring


3 Answers

Use the Mycila license plugin instead, it will do what you want (no segment markers), is simpler in someways and is under much more active development. I was banging my head with this plugin as well, until I came across this comment

like image 62
Antony Stubbs Avatar answered Oct 30 '22 17:10

Antony Stubbs


As shown in the other answer, these tags are required for finding and updating the license information. One thing you can do is make them less annoying...

In my project, I have changed them to something a bit more pretty:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>license-maven-plugin</artifactId>
    <version>1.9</version>
    <configuration>
        <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
        <processStartTag>========================LICENSE_START=================================</processStartTag>
        <processEndTag>=========================LICENSE_END==================================</processEndTag>
    </configuration>
    ...
</plugin>

The lines with === look better to me than the default #%L lines, which look like accidentally left garbage to me :-)

The only requirement for these tags is to be unique, hence the _START and _END part. I've also found that any space characters in the tags are deleted before inserting into the file.

like image 32
nwinkler Avatar answered Oct 30 '22 16:10

nwinkler


The documentation for version 1.9 (latest at time of writing) says these are mandatory delimiters for it to find the header.

(1) # % L
(2) Project description
(3) %%
(4) Copyright (C) 2010 your organization
(5) %%
(6) License content
(7) # L %
  1. The start process tag used to detect begin of header (NEVER suppress it).
  2. Project description section
  3. Header section delimiter
  4. Copyright section of the file (see next section for detail)
  5. Header section delimiter
  6. License section
  7. The end process tag used to detect end of header (NEVER suppress it).
like image 26
msbarnar Avatar answered Oct 30 '22 15:10

msbarnar