Recently, i got a task where licensing was required to be added. I have done such tasks using ant in the past but this time I was supposed to use maven. Some quick search made it clear that maven provides a plugin to do such activities but the documentation was not upto the mark (or i can say it was a bit confusing or too generic). To save other people from such situation I am going to demonstrate it using a simple example.
Lets suppose you want to have licensing information given below in all java files of your project:
/**
* Copyright (C) 2014 My Coaching Company. All rights reserved This software is the confidential
* and proprietary information of My Coaching Company. You shall not disclose such confidential
* information and shall use it only in accordance with the terms of the license agreement you
* entered into with My Coaching Company.
*
*/
Here are steps to do so:
1. Create a txt file named License.txt and place it in parallel with pom.xml and make sure that your license file should not contain comments like /** ... */. It should look like,
Copyright (C) 2014 My Coaching Company. All rights reserved This software is the confidential and proprietary information of My Coaching Company. You shall not disclose such confidential information and shall use it only in accordance with the terms of the license agreement you entered into with My Coaching Company.
2. Add following snippet to pom.xml
<properties>
<license.dir>${basedir}</license.dir>
</properties>
3. Now add plugin configuration for adding license to java files in maven project,
<!-- License information -->
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.10.b1</version>
<configuration>
<header>${license.dir}/license.txt</header>
<properties>
<project>
${project.name}
</project>
<founder>${project.organization.name}</founder>
<year>${project.inceptionYear}</year>
<website>${founder-website}</website>
</properties>
<includes>
<include>src/main/java/**</include>
<include>src/test/java/**</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mycila</groupId>
<artifactId>licenses</artifactId>
<version>1</version>
</dependency>
</dependencies>
</plugin>
Add a comment