Th *_*Ä s 2 configuration maven
我想对 maven 过滤器标签以及它如何对应于插件 properties-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>
Run Code Online (Sandbox Code Playgroud)
根据我的研究过滤器定义了其中包含需要替换的变量的文件。“properties-maven-plugin”是否从文件标签中定义的文件中提供这些变量?
首先,要让 Maven 过滤器真正起作用,您需要为某些目录启用资源过滤,例如
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
Run Code Online (Sandbox Code Playgroud)
仅列出一些过滤器文件没有任何作用,因为这些读取值不会在任何地方使用。
现在,在这里解释差异。目标read-project-properties是properties-maven-plugin从属性文件中读取一些值并将它们存储为 Maven 变量。它在 Maven 生命周期 ( <phase>initialize</phase>) 的早期执行,因此它们几乎从一开始就可用。所以,我们可以说这是通过将它们放入一些常规性的文件,而不是可能巨大的外部化的Maven性能的方式<properties>块pom.xml。这里重要的是,Maven 变量用于资源过滤。
现在,<filters>标签。这些文件不提供 Maven 项目变量。它们提供仅用于资源过滤的变量。
因此,在资源过滤的上下文中,实际行为非常相似。读取的属性properties-maven-plugin将用于资源过滤以及从过滤器文件中读取的属性。但是,读取的那些properties-maven-plugin也将作为 Maven 项目属性可用,因此它们可以用于例如插件的配置或任何其他与 POM 相关的东西。