当我升级 Maven 时,我遇到了属性插件的问题:
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
在我的 pom 中,我定义了属性:
<?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>
<artifactId>...</artifactId>
<groupId>...</groupId>
<packaging>war</packaging>
<version>1.0.10-SNAPSHOT</version>
<name>...</name>
<properties>
<!-- application -->
<appname>appname1</appname>
</properties>
<build>
... // here I dont have properties plugin because I dont need them
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${appname}</warName> // here is stil name in pom
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
</resource>
</webResources>
</configuration>
</plugin>
...
</build>
<profiles>
<profile>
<id>config</id>
<activation>
<property>
<name>config</name>
</property>
</activation>
<properties>
<config>${basedir}/../config/${config}/build.properties</config>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${config}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
...
</dependencies>
</project>
然后我有个人资料:
<profile>
<id>config</id>
<activation>
<property>
<name>config</name>
</property>
</activation>
<properties>
<konfig>${basedir}/../config/${config}/build.properties</konfig>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${konfig}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
我可以在其中指定另一个具有属性的文件:
文件包含:
appname=appname2
所以逻辑是当我运行 mvn 时......没有配置文件属性是从 pom.xml 中获取的。如果使用配置文件,它应该使用配置文件中的属性。这适用于 maven 2,但 maven 3 仍然从 pom 获取属性。有没有办法解决它?
这里: http: //mojo.codehaus.org/properties-maven-plugin/read-project-properties-mojo.html 写的是:
属性:
Requires a Maven 2.0 project to be executed.
这意味着maven 3不支持这个插件?