Question

I have a multi-module project in which I'm trying to set up the license plugin to manage all the licenses. Here's the project setup:

─── transfuse-project
    ├── examples
    │   ├── helloAndroid
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── integrationTest
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── pom.xml
    │   └── ...
    ├── transfuse
    │   ├── pom.xml
    │   ├── ...
    ├── transfuse-api
    │   ├── pom.xml
    │   ├── ...
    ├── NOTICE
    └── pom.xml

Each pom.xml inherits from the transfuse-project pom.xml. In the project pom.xml I have set up the license plugin to apply the NOTICE to the relevant files:

        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <version>1.9.0</version>
            <configuration>
                <header>NOTICE</header>
                <includes>
                    <include>**/*.java</include>
                    <include>**/*.xml</include>
                </includes>
                <excludes>
                    <exclude>**/.*/**</exclude>
                    <exclude>target/**</exclude>
                    <exclude>**/AndroidManifest.xml</exclude>
                </excludes>
                <properties>
                    <year>2013</year>
                    <name>John Ericksen</name>
                </properties>
                <useDefaultExcludes>true</useDefaultExcludes>
                <strictCheck>true</strictCheck>
            </configuration>
            <executions>
                <execution>
                    <id>check-headers</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

This configuration works if I build directly off of the root (transfuse-project). The problem arises when I build the integrationTest example or api directly. Maven cannot find the NOTICE file I provided in the project root:

[ERROR] Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:check (check-headers) on project transfuse-api: Some files do not have the expected license header -> [Help 1]

And what's worse, it finds another dependency's NOTICE file. If I run mvn license:format in a sub-module it replaces all of the module's headers with the dependency's NOTICE file.

I believe I can add a NOTICE file within each sub-module to fix this problem and configure each sub-module pom with its own license plugin, but I would like to avoid that duplication if possible. Is there some configuration or setup that will work with my project setup?

Was it helpful?

Solution

Try to use an absolute path by using

<header>${basedir}/NOTICE</header>

If this doesn't work, try to set a property to and in the parent module's basedir and use it:

<header>${main.basedir}/NOTICE</header>

A third option is setting a property at runtime:

mvn clean install -Dmain.basedir=path/to/main/basedir

Edit:

Ok, a whole other option is to execute the maven-dependency-plugin before your license plugin. But you have to make sure the parent attaches the NOTICE (with maven-assembly-plugin plugin)

<plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>2.6</version>
         <executions>
           <execution>
             <id>unpack-parent</id>
             <phase>verify</phase>
             <goals>
               <goal>unpack</goal>
             </goals>
             <configuration>
               <artifactItems>
                 <artifactItem>
                   <groupId>parent</groupId>
                   <artifactId>parent</artifactId>
                   <version>parent</version>
                   <type>pom</type>
                   <overWrite>false</overWrite>
                   <outputDirectory>${project.build.directory}/license</outputDirectory>
                   <includes>NOTICE</includes>
                 </artifactItem>
               </artifactItems>
             </configuration>
           </execution>
         </executions>
       </plugin>

The header changes then in:

<header>${project.build.directory}/license/NOTICE</header>

Edit2:

I came across the find-maven-plugin. I think this could work:

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>find-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>find-notice-file</id>
            <goals>
                <goal>find</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
                <propertyName>notice.file</propertyName>
                <file>NOTICE</file>
            </configuration>
        </execution>
    </executions>
</plugin>

OTHER TIPS

There's actually a much easier way to do this. Just set the aggregate tag to true in the configuration. Here's the full maven-license-plugin definition:

<plugin>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <version>1.10.b1</version>
    <configuration>
        <header>etc/header.txt</header>
        <aggregate>true</aggregate>
        <includes>
            <include>**/*.java</include>
        </includes>
    </configuration>
</plugin>

You then just need to have a file called header.txt in etc/header.txt in the parent root directory.

Try your example with this two configuration properties set:

<plugin>
  <groupId>com.mycila</groupId>
  <artifactId>license-maven-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    <header>/NOTICE</header>
    <aggregate>true</aggregate>
  </configuration>
</plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top