我已经将这个项目简化为尽可能简单。我使用maven-echo-plugin1。这个项目所做的就是根据deluxe
配置文件是否激活来响应一个特定的语句。如果我没有使用豪华配置文件,项目将打印出This is the base configuration
。如果我使用的是豪华配置文件,项目将打印出This is the deluxe configuration
。
我有以下父元素:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>name.weintraub</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<profiles>
<profile>
<id>deluxe</id>
<activation>
<property>
<name>deluxe</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>echo</goal>
</goals>
<phase>validate</phase>
<configuration>
<echos>
<echo>This is the deluxe configuration</echo>
</echos>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>echo</goal>
</goals>
<phase>validate</phase>
<configuration>
<echos>
<echo>This is the base configuration</echo>
</echos>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
如果我运行:
$ mvn validate
这将打印This is the base configuration
。
如果我运行:
$ mvn -Pdeluxe validate
这将打印出This is the deluxe configuration
So far So good:
我现在创建一个子窗体:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<deluxe>true</deluxe>
</properties>
<parent>
<groupId>name.weintraub</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>name.weintraub</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
</project>
注意,我已经在文件的开头将属性deluxe
设置为true
。
当我运行:
$ mvn validate
输出This is the base configuration
。
如果我像这样运行:
mvn -Ddeluxe=true validate
然后输出This is the deluxe configuration
。如果我做
mvn -Pdeluxe validate
输出This is the deluxe configuration
。
因此,我可以看到子程序正在拾取父概要文件,如果我直接在命令行上激活概要文件,或者通过使用属性激活概要文件。然而,即使我在pom本身设置了属性,我的项目似乎也没有拾取父节点的配置文件。
为什么?
1我使用0.1版本,因为这是Maven Central的最新版本,它在1.0版本中被称为maven-echo-plugin
。其他文档相同
配置文件只能使用系统属性(即命令行)/环境变量以及JDK和OS来激活,而不能使用pom属性。(请参阅构建配置文件介绍:"目前,此检测仅限于JDK版本的前缀匹配,系统属性的存在或系统属性的值。")
所以,你的方法不能那样工作。您可能想看看非对称配置文件作为一种选择。