Parent properties inside maven antrun plugin

谁都会走 提交于 2019-12-05 07:38:11

I don't know exactly why the ${project.parent.basedir} is not "available" from AntRun, maybe it's just not supported (see http://jira.codehaus.org/browse/MNG-3597).

Here is an horrible workaround using 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>

I'm not proud of it, but it kinda "works" (if a string representation of the path to the parent basedir is ok for you):

$ mvn validate
[INFO] Scanning for projects...
...
[INFO] --- maven-antrun-plugin:1.6:run (render-parameter-sql) @ Q4040778 ---
[INFO] Executing tasks

main:
     [echo] project.artifactId        : Q4040778
     [echo] project.parent.basedir    : ${project.parent.basedir}
     [echo] main.basedir              : /home/pascal/Projects/stackoverflow
     [echo] project.basedir           : /home/pascal/Projects/stackoverflow/Q4040778
     [echo] project.build.directory   : /home/pascal/Projects/stackoverflow/Q4040778/target
[INFO] Executed tasks
...

But I need to say that what you want to do (from this module I need the root of the parent to reach other modules) is a bad practice, modules should be self contained and not tightly coupled.

I do not recommend using what I posted :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!