I am trying to add a license file to all of my jars when executing a maven build. I have the license on each class file, but I am looking to add License.txt to each META-INF folder within each jar
My project has a master pom, which has half dozen modules, those modules then have modules of their own, and eventually get to a project that generates a /target/<.jar-file>. The build and the class level licenses are working, I am just looking to add a physical License.txt into the META-INF folder.
My file is stored (relative to the master POM) in /src/resources/src-license.txt. I really need the automated method to ensure that if/when the license changes, I dotn have to update 50 files, I can just update the one, which is then copied out to the other locations.
I have tried using
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/resources</directory>
<targetPath>/META-INF</targetPath>
<includes>
<include>src-license.txt</include>
</includes>
</resource>
</resources>
....
</build>
But that doesnt seem to do the trick. I have also tries some alternatives to the output path, such as ${project.build.outputDirectory}/META-INF, or */META_INF, also to no avail. Does anyone have some experience on how to accomplish this? Thanks
Also, I use the maven-license-plugin to ensure that each class file has the license info pasted into it, and that functions as intended. But again, that inside the class files, I am looking for an external .txt file in each <*.jar>/META-INF/
Using resources from parent relativePath is at least difficult (what if you have a complex directory structure?).
A simple and clean way can be to create a separate module containing your src-license.txt file. Then make it a dependency of your modules and unzip it (dependency:unpack-dependencies) @ generate-resources phase, inside target/classes.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-license</id>
<phase>generate-resources</phase>
<goals><goal>unpack</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.acme</groupId>
<artifactId>com.acme.license</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With