DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Build a New API Quickly Using Spring Boot and Maven
  • Configurable Feign Client Retry With Reusable Library and DRY
  • Using Lombok Library With JDK 23
  • Enhancing Software Quality with Checkstyle and PMD: A Practical Guide

Trending

  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  • Microsoft Azure Synapse Analytics: Scaling Hurdles and Limitations
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • How to Configure and Customize the Go SDK for Azure Cosmos DB
  1. DZone
  2. Coding
  3. Java
  4. Adding License Information Using Maven

Adding License Information Using Maven

By 
Prateek Jain user avatar
Prateek Jain
·
Oct. 07, 14 · Interview
Likes (1)
Comment
Save
Tweet
Share
15.2K Views

Join the DZone community and get the full member experience.

Join For Free

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>
4. Now you are all set to fire the command 
     mvn license:format
This will add license information on top of java code.
Note: If you have projects under subproject something like
 project ---|
                 | --> sub-project
                 | --> sub-project2

then you are required to add following snippet into the pom.xml of sub-projects:

<properties>
    <license.dir>${project.parent.basedir}</license.dir>
</properties>

I hope this should help lots of developers around. This is one of the most simple usage of this plugin for more please refer to the official site.


Apache Maven

Published at DZone with permission of Prateek Jain, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build a New API Quickly Using Spring Boot and Maven
  • Configurable Feign Client Retry With Reusable Library and DRY
  • Using Lombok Library With JDK 23
  • Enhancing Software Quality with Checkstyle and PMD: A Practical Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: