配置文件应该非常适合这个。根据Maven 构建配置文件文档中的信息,这应该不起作用。具体来说,他们说
build as specified inside of a profile is not a full implementation of the traditional
build POM element. This build is really another class in the model - from which the POM
build is derived - and only allows the plugins and pluginManagement subelements when
defined here. This sidesteps any issues with secondary validation after the pom.xml is
parsed in this case.
但我只是对其进行了测试,它通过在内部包含一个带有资源定义的构建元素来包含适当的资源。
在您的 pom 中,您需要为每个 webapps 包含一个配置文件。例如,在我的测试中,我做了以下事情:
<profile>
<id>abc</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>abc</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>xyz</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>xyz</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
然后,我有一个目录 abc,其中包含一个文件 abc.properties,另一个 xyz 具有相应的 xyz.properties 文件。
对于所有共享资源,您将拥有一个元素,该元素还具有一个包含您希望在每个 web 应用程序中使用的所有资源的元素。
最后,当您构建时,您将指定要构建的 webapp 的配置文件,例如 mvn -P abc clean install
使用这种方法可能会遇到的一个大问题是,构建的每个工件都将具有相同的名称,并且其中一个会覆盖本地存储库中的另一个。