Search code examples
mavenlicensinglicense-maven-plugin

What data to expect in license-maven-plugin third party license FreeMarker template?


I'm using the Mojo License Maven plugin to generate a list of third party licenses. According to the documentation I could use a custom FreeMarker template to format the file using the fileTemplate parameter, but there is no documentation on the data that will be passed to the FreeMarker template. There is a link on the examples page to existsing templates, but that link is broken.


Solution

  • After some searching I found the template on GitHub:

    ...
    
    <#-- To render the third-party file.
     Available context :
     - dependencyMap a collection of Map.Entry with
       key are dependencies (as a MavenProject) (from the maven project)
       values are licenses of each dependency (array of string)
     - licenseMap a collection of Map.Entry with
       key are licenses of each dependency (array of string)
       values are all dependencies using this license
    -->
    <#function licenseFormat licenses>
        <#assign result = ""/>
        <#list licenses as license>
            <#assign result = result + " (" +license + ")"/>
        </#list>
        <#return result>
    </#function>
    <#function artifactFormat p>
        <#if p.name?index_of('Unnamed') &gt; -1>
            <#return p.artifactId + " (" + p.groupId + ":" + p.artifactId + ":" + p.version + " - " + (p.url!"no url defined") + ")">
        <#else>
            <#return p.name + " (" + p.groupId + ":" + p.artifactId + ":" + p.version + " - " + (p.url!"no url defined") + ")">
        </#if>
    </#function>
    
    <#if dependencyMap?size == 0>
    The project has no dependencies.
    <#else>
    Lists of ${dependencyMap?size} third-party dependencies.
        <#list dependencyMap as e>
            <#assign project = e.getKey()/>
            <#assign licenses = e.getValue()/>
        ${licenseFormat(licenses)} ${artifactFormat(project)}
        </#list>
    </#if>
    

    It uses this LicenseMap