要在多个项目之间共享资源(属性文件),我想使用maven-remote-resources-plugin
。
共享属性文件应该由Maven过滤,以便实际程序可以检索一些构建信息。
因为属性文件总是相同的,我的目标是让父pom处理该文件的处理。 因此,项目的结构是:
理想情况下,Project X的pom.xml不包含有关属性文件的信息。
其实我真的很接近我的目标。
在父母pom中我添加了:
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>process-remote-resources</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<resourceBundles>
<resourceBundle>com.gillesB:resourceJar:1.0</resourceBundle>
</resourceBundles>
<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
</configuration>
</execution>
</executions>
</plugin>
我还将依赖项添加到com.gillesB:resourceJar:1.0
。
当我构建Project X时,属性文件将写入target/maven-shared-archive-resources
,并且还会添加到生成的jar
中。
但文件中的占位符不会替换为实际值。
如果我将以下内容添加到Project X pom:
<resource>
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
<filtering>true</filtering>
</resource>
jar中的属性文件被过滤。 但要实现这一目标,必须改变孩子的皮肤。
由于我没有在documentation中看到<resource>
而process
- 目标有自己的过滤器参数,我预计过滤功能可以直接使用。
我检查了调试日志,似乎文件被复制了两次:
[INFO] Copying 1 resource
[DEBUG] file app.properties has a filtered file extension
[DEBUG] filtering D:\projectX\target\maven-shared-archive-resources\app.properties to D:\projectX\target\classes\app.properties
[DEBUG] resource with targetPath null
directory D:\pX\target\maven-shared-archive-resources
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 1 resource
[DEBUG] file app.properties has a filtered file extension
[DEBUG] copy D:\projectX\target\maven-shared-archive-resources\app.properties to D:\projectX\target\classes\app.properties
[DEBUG] no use filter components
如果省略<resource>
,则只有第二部分出现在日志中。
在查找no use filter components
后,最有用的结果是source code。
不幸的是,这对我来说并不是很有用。