Maven:属性未被替换

发布于 2024-09-01 14:32:51 字数 1522 浏览 5 评论 0原文

我在项目中使用 install4j 的 Maven 插件,位于此处。该插件允许您使用 部分将变量传递给 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

这是插件的错误吗?如果是这样,需要进行哪些更改才能实现替换?

I'm using a maven plugin for install4j in my project, located here. That plugin lets you pass variables to install4j using the <compilerVariables> section. Here's the relevant section of my 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>

The problem is that ${settings.localRepository} is not being substituted with the actual directory when I run the plugin. Here's the command line script that install4j is generating:

[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

Is this the fault of the plugin? If so, what needs to change to allow the substitution to happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剑心龙吟 2024-09-08 14:32:51

以下 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 有关吗?

The following POM just works for me (with 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>

And running mvn process-ressources produces the following output:

$ 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] ------------------------------------------------------------------------

Does the above work for you? Are you using M2Eclipse? Could it be related to MNGECLIPSE-299?

云朵有点甜 2024-09-08 14:32:51

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

The plugin in question accepts a parameter which is a Properties instance. For whatever reason, expressions used to configure Properties instances are not automatically evaluated. I had to change the plugin to use a org.apache.maven.plugin.PluginParameterExpressionEvaluator to evaluate ${settings.localRepository}.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文