Fork me on GitHub

Download Licenses Examples

This page provides examples of how to use the download-licenses goal. By default, the download-licenses goal will attempt to resolve the license of each project dependency. These files will be downloaded to a local directory to be included in the final packaging of the project if desired. The licenses are downloaded based on the url field of the dependency POM.

After downloading the license files, the plugin will create a summary file in XML format which describes the license(s) associated with each dependency. Note that subsequent runs of the plugin will avoid downloading the licenses unless the local file exists or forceDownload is set to true.

Basic Example

This example shows how to configure the download-licenses goal for basic usage.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>download-licenses</id>
            <goals>
              <goal>download-licenses</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Next run your build:

mvn package

For the download-licenses goal, licenses will by default be downloaded into the directory target/generated-resources/licenses. This can be configured using the licensesOutputDirectory parameter.

Manual License Configuration

By default the plugin will look at the POM of each dependency for license information. However, not all POMs have been configured with the correct license information. In these cases, the required license information can be configured manually. By default, the plugin will look for a file called src/license/licenses.xml. This file contains manually configured license information which will be merged with information from the dependency POMs to create the final license report. The location of this file can be configured using the licensesConfigFile parameter The following is an example license config file.

<?xml version="1.0"?>

<licenseSummary xmlns="http://mojo.codehaus.org/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://mojo.codehaus.org/ licenses.xsd">
  <dependencies>
    <dependency>
      <groupId>com.wutka</groupId>
      <artifactId>dtdparser</artifactId>
      <licenses>
        <license>
          <name>GNU Lesser General Public License</name>
          <url>http://www.gnu.org/licenses/lgpl.txt</url>
          <distribution>repo</distribution>
        </license>
      </licenses>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <licenses>
        <license>
          <name>MIT License</name>
          <url>http://www.opensource.org/licenses/mit-license.php</url>
        </license>
      </licenses>
    </dependency>
  </dependencies>
</licenseSummary>

The generated license report follows the same XML format as the manual license config file.