Do you know what is LicenseMain task failure in Gradle?

Let me share my experience on what is LicenseMain task failure and how did I resolved it. Since you’re reading this post, it’s safe to assume that you already know about Gradle and use of Copyright License Header. Still, I will like to share a brief about Gradle and Copyright License Header.

What is Gradle?

In short, Gradle is an open source build tool which uses a Groovy-based domain-specific language unlike Maven and Ant which uses XML and is mainly used to automate task.In general it helps in building software faster and does increases developers productivity.

What is Copyright License Header?

Copyright license headers permit other developers to exam the file to perceive the terms of work even when the file is distributed solely, without a license header it is considered that the developer of the file has reserved all rights including right to copy,modify and redistribute.

What does Gradle task do?

A Gradle task is a job that a build performs. There can various types of Gradle task like creating a jar, generating Java-doc etc.

What is LicenseMain task failure in Gradle?

In order to explain this issue I have created a simple Gradle project .

Below is the project structure of my Gradle project.

Gradle project

Every Gradle project contain an important Gradle file mostly know as “build.gradle” .

Note you can use any other name apart from build.gradle , the name of the Gradle file is not restricted. In real time scenario, where you have multiple nested project you can create the Gradle file according to your nested project name

Before starting what is LicenseMain failure, let me explain a bit about build.gradle file.

Below is the code snippet of my “build.gradle” file.

build.gradle file

As we know gradle is mainly used to set up common type of projects . Here you can see in the above file how this is achieve.We need to add few plugins to build a particular type of project, that is why few plugins are applied to my project.The task “apply plugin” extends the project’s capabilities.

In my case, you can see a license plugin apart from other java,spring boot and eclipse plugin.

Let me tell you this is the plugin which is responsible for the LicenseMain failure issue. In case your project do not need Copyright License Headers you can simply remove this plugin and its dependency and resolve this issue but that is not the solution as all real time projects needs licensing.

What is License Gradle Plugin?

License Gradle Plugin is mainly used to scan every source set and report warnings. It imposes source files to include a provided header, For example a LICENSE file.This plugin creates format task, which is responsible for properly formatting and applying the specified header. Apart from this, it also reports on the licenses of project’s dependencies.

This License Gradle Plugin has two main task , one for checking the consistency and one to apply the header .

  1. LicenseMain and LicenseTest (This comes under LicenseCheck task)
  2. LicenseFormatMain and LicenseFormatTest (This comes under LicenseFormat task)

Now the issue that I faced comes under LicenseCheck task.

Below is the screen of the LicenseMain failed issue due to missing LICENSE file.

LicenseMain failure task

This task mainly fails in two cases one if you have not added the LICENSE header file and another if you have not applied the correct header to the source files.

How do we configure the LICENSE file ?

Create a file named LICENSE ,place it under root directory of the project and update the gradle file with this code snippet.

Below is the code snippet of the LICENSE file


Below is the screen of the sample project where the LICENSE file is placed.

Project structure where LICENSE file is placed

Once the LICENSE file is available, add this code snippet to the build.gradle file, license {header rootProject.file(‘LICENSE’)}

Below is the code snippet of the sample project.

build.gradle file with code snippet to detect LICENSE file

Even though the LICENSE file is available, the task LicenseMain failure will still occur but this time the failure will indicate different message.

Below is the screen of the LicenseMain failed issue due to missing LICENSE header in the file.

In order to resolve this issue, we need to add a License Header to the file.

Below is the code snippet of the sample project file. file with Copyright License Header

Note: You must create the LICENSE file without any extension otherwise it will not detect the LICENSE file. In my case, initially I created a LICENSE file with .txt extension and as a result even after adding it to the root folder of the project, I was getting failure message LICENSE header does not exist .

Now you may have certain requirement where you don't want to add the License Header to one of your project’s source file.In my case, I have added a properties file name under resources folder and I don't want to add a License Header to this file.

In this case, again LicenseMain failure will occur because the file does not have a license header.

Below is the screen of LicenseMain failure issue of my sample project.

License Failure due to missing header in

In order to resolve this issue, we need to add this exclude “**/*.properties" code snippet in the build.gradle file. This will exclude all files with .properties extension.

Note: Similarly you exclude group files extension, for example — excludes([“**/*.txt”, “**/*.conf”])

Below is the code snippet of my sample project.

build.gradle file with exclude properties

This is one use case scenario that I am trying to explain in this article. Apart from this, there are so many other interesting properties that are available in this license plugin which can help to resolve some other use case scenario. My code is as per Gradle 1.x/2.0, gradle-license-plugin 0.10.0 (and earlier). The higher versions, the code snippet may be little different.

In order to get complete details about license plugin please follow the below link.

Hope this will help my fellow developers to resolve license plugin related issues in there project .

I am just trying to share my experiences and open to questions that will help me to create more valuable resources for other developers.Please share your feedback whoever reads this content, this will in a way encourage me. Also you can post questions if you have more queries.

References: , and




Software engineer. Open to learn new things.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Measurement and Analysis in Agile Software Development

[Linux Security] Understanding Linux Capabilities Series (Part I)

Managing multiple Git configurations

Using a dual model for rule expressivity and performance

Lambda Triggers & Read-Only Permissions with AWS Amplify

Noindex, Nofollow and Disallow: What are They?

CSS’s class naming convention.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mousumi Hazarika

Mousumi Hazarika

Software engineer. Open to learn new things.

More from Medium

Getting Back on Track

e-ID Card Portal - a UX Documentation

“It requires empathy” — tips on tenant liaison for whole house retrofit

Primordial Chaos