Maven:没有被替换的属性

时间:2010-05-13 17:04:25

标签: maven-2 replace properties substitution

我在我的项目中使用了一个maven插件来安装install4j,位于here。该插件允许您使用<compilerVariables>部分将变量传递给install4j。这是我的pom的相关部分:

<plugin>
    <groupId>com.google.code.maven-install4j</groupId>
    <artifactId>maven-install4j-plugin</artifactId>
    <version>0.1.1</version>
    <configuration>
        <executable>${devenv.install4jc}</executable>
        <configFile>${basedir}/newinstaller/ehd.install4j</configFile>
        <releaseId>${project.version}</releaseId>
        <attach>false</attach>
        <skipOnMissingExecutable>false</skipOnMissingExecutable>
        <compilerVariables>
            <property>
                <name>m2_home</name>
                <value>${settings.localRepository}</value>
            </property>
        </compilerVariables>
    </configuration>
</plugin>

问题是当我运行插件时$ {settings.localRepository}没有被实际目录替换。这是install4j正在生成的命令行脚本:

[INFO] Running the following command for install4j compile: /bin/sh -c /home/zach/install4j/bin/install4jc --release=9.1-SNAPSHOT --destination="/home/zach/projects/java/ehdtrunk/target/install4j" -D m2_home=${settings.localRepository} /home/zach/projects/java/ehdtrunk/newinstaller/ehd.install4j

这是插件的错吗?如果是这样,需要改变什么以允许替换发生?

2 个答案:

答案 0 :(得分:1)

以下POM适用于我(使用Maven 2.2.1):

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow</groupId>
  <artifactId>Q2828732</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    ...
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>validate</phase>
            <configuration>
              <tasks>
                <echo>${settings.localRepository}</echo>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

运行mvn process-ressources会产生以下输出:

$ mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q2828732
[INFO]    task-segment: [validate]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
     [echo] /home/pascal/.m2/repository
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu May 13 19:28:38 CEST 2010
[INFO] Final Memory: 3M/54M
[INFO] ------------------------------------------------------------------------

以上是否适合您?你在使用M2Eclipse吗?它可能与MNGECLIPSE-299相关吗?

答案 1 :(得分:1)

有问题的插件接受一个属性实例的参数。无论出于何种原因,都不会自动评估用于配置Properties实例的表达式。我不得不更改插件以使用org.apache.maven.plugin.PluginParameterExpressionEvaluator来评估$ {settings.localRepository}。