我正在尝试在执行maven构建时将许可文件添加到我的所有jar中。我在每个类文件上都有许可证,但我希望将License.txt添加到每个jar中的每个META-INF文件夹中
我的项目有一个主pom,它有六个模块,那些模块然后有自己的模块,最终到达一个生成/target/<.jar-file>的项目。构建和类级别许可证正在运行,我只是想将物理License.txt添加到META-INF文件夹中。
我的文件(相对于主POM)存储在/src/resources/src-license.txt中。我真的需要自动化方法来确保如果/当许可证发生变化时,我必须更新50个文件,我可以更新一个文件,然后将其复制到其他位置。
我尝试过使用
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/resources</directory>
<targetPath>/META-INF</targetPath>
<includes>
<include>src-license.txt</include>
</includes>
</resource>
</resources>
....
</build>
但这似乎并没有成功。我也尝试了输出路径的一些替代方法,例如$ {project.build.outputDirectory} / META-INF或* / META_INF,也无济于事。有没有人有一些如何实现这一目标的经验?感谢
此外,我使用maven-license-plugin确保每个类文件都粘贴了许可证信息,并且按预期运行。但同样,在类文件中,我在每个&lt; * .jar&gt; / META-INF /
中寻找外部.txt文件答案 0 :(得分:3)
使用来自parent relativePath的资源至少是困难的(如果你有一个复杂的目录结构怎么办?)。
一种简单而干净的方法可以是创建一个包含src-license.txt文件的独立模块。然后使它成为模块的依赖项并将其解压缩(依赖:unpack-dependencies)@ generate-resources阶段,在目标/类中。
<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>