【问题标题】:Parent properties inside maven antrun pluginmaven antrun 插件中的父属性
【发布时间】:2010-10-28 07:41:20
【问题描述】:

有一个多模块项目。在孩子内部,我需要做一些复杂的事情(部署到应用程序服务器的集成测试等等)。所以有一个集成测试孩子,从这个模块我需要父模块的根才能到达其他模块。我不想使用“..”。在 integrationtest POM 中有一个属性:

<properties>
 <main.basedir>${project.parent.basedir}</main.basedir>
    ...
</properties>

还有一个antrun插件,内容如下:

<plugins>
 <plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
   <execution>
    <id>render-parameter-sql</id>
    <phase>validate</phase>
    <goals>
     <goal>run</goal>
    </goals>
    <configuration>
     <tasks>
      <echoproperties/>
     </tasks>
    </configuration>
   </execution>
  </executions>
 </plugin>
</plugins>

在输出中,main.basedir 没有被解析:

main:
[echoproperties] #Ant properties
[echoproperties] #Thu Oct 28 09:32:13 CEST 2010
[echoproperties] ant.core.lib=C\:\\Users\\gaborl\\.m2\\repository\\org\\apache\\ant\\ant\\1.8.1\\ant-1.8.1.jar
...
[echoproperties] main.basedir=${project.parent.basedir}
[echoproperties] maven.dependency.antlr.antlr.jar.path=C\:\\Users\\gaborl\\.m2\\repository\\antlr\\antlr\\2.7.6\\antlr-2.7.6.jar

在真正生气之后,我决定问你如何解决这个问题......

【问题讨论】:

    标签: maven-2 multi-module maven-antrun-plugin


    【解决方案1】:

    我不知道确切地为什么 ${project.parent.basedir} 不是 AntRun 的“可用”,也许它只是不受支持(参见 http://jira.codehaus.org/browse/MNG-3597)。

    这是一个使用 gmaven 的可怕解决方法:

    <plugin>
      <groupId>org.codehaus.gmaven</groupId>
      <artifactId>gmaven-plugin</artifactId>
      <version>1.3</version>
      <executions>
        <execution>
          <id>set-custom-property</id>
          <phase>validate</phase>
          <goals>
            <goal>execute</goal>
          </goals>
          <configuration>
            <source>
              project.properties.setProperty('main.basedir', project.parent.basedir.toString())
            </source>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.6</version>
      <executions>
        <execution>
          <id>render-parameter-sql</id>
          <phase>validate</phase>
          <goals>
            <goal>run</goal>
          </goals>
          <configuration>
            <target>
              <echo>project.artifactId        : ${project.artifactId}</echo>
              <echo>project.parent.basedir    : ${project.parent.basedir}</echo>
              <echo>main.basedir              : ${main.basedir}</echo>
              <echo>project.basedir           : ${project.basedir}</echo>
              <echo>project.build.directory   : ${project.build.directory}</echo>
            </target>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    我并不为此感到自豪,但它有点“有效”(如果您可以使用字符串表示的父 basedir 路径):

    $ mvn 验证 [INFO] 正在扫描项目... ... [信息] --- maven-antrun-plugin:1.6:run (render-parameter-sql) @ Q4040778 --- [INFO] 执行任务 主要的: [回声] project.artifactId:Q4040778 [回声] project.parent.basedir : ${project.parent.basedir} [echo] main.basedir : /home/pascal/Projects/stackoverflow [回声] project.basedir:/home/pascal/Projects/stackoverflow/Q4040778 [回声] project.build.directory:/home/pascal/Projects/stackoverflow/Q4040778/target [INFO] 已执行的任务 ...

    但我需要说的是你想要做的(从这个模块我需要父模块的根才能到达其他模块)是一个不好的做法,模块应该是自包含的,而不是紧密耦合的。

    我不建议使用我发布的内容:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多