我想解释一下 maven 过滤器标签以及它如何与插件属性 maven-plugin 中的文件标签相对应。
有问题的个人资料:
<profile>
<id>local-spm-caefeeder-preview</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<quiet>true</quiet>
<files>
<file>${main.basedir}/src/config/global.properties</file>
<file>${main.basedir}/src/config/caefeeder/caefeeder_global.properties</file>
<file>${main.basedir}/src/config/caefeeder/caefeeder_preview.properties</file>
<file>${main.basedir}/src/config/local.properties</file>
<file>${main.basedir}/src/config/${user.name}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<filters>
<filter>${main.basedir}/src/config/caefeeder/caefeeder_global.properties</filter>
<filter>${main.basedir}/src/config/caefeeder/caefeeder_preview.properties</filter>
<filter>${main.basedir}/src/config/local.properties</filter>
<filter>${main.basedir}/src/config/${user.name}.properties</filter>
</filters>
</build>
</profile>
从我的研究过滤器定义文件,其中有需要替换的变量。"properties-maven-plugin"是否从文件标签中定义的文件中提供这些变量?
首先,要让 Maven 过滤器真正工作,您需要为某些目录启用资源过滤,例如
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
仅列出一些过滤器文件没有任何作用,因为这些读取值不会在任何地方使用。
现在,这里解释差异。目标read-project-properties
properties-maven-plugin
从属性文件中读取一些值并将其存储为 Maven 变量。它在Maven生命周期(<phase>initialize</phase>
)的早期执行,因此它们几乎从一开始就可用。因此,我们可以说这是一种通过将Maven属性放入一些常规属性文件中而不是pom.xml
中可能的巨大<properties>
块来外部化Maven属性的方法。这里重要的是,Maven变量用于资源过滤。
现在,<filters>
标签。这些文件不提供 Maven 项目变量。它们提供仅用于资源筛选的变量。
因此,在资源过滤的上下文中,实际行为几乎相同。properties-maven-plugin
读取的属性将用于资源筛选以及从筛选器文件中读取的属性。但是,properties-maven-plugin
读取的那些也将作为Maven项目属性提供,因此它们可以用于插件的配置或任何其他与POM相关的东西。