maven antrun 插件内的父属性
有一个多模块项目。在孩子内部,我需要做一些复杂的事情(集成测试与部署到应用程序服务器等)。所以有一个集成测试子模块,从这个模块我需要父模块的根才能到达其他模块。我不想使用“..”。 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
在变得非常生气之后,我决定问你如何解决这个问题......
There is a multi-module project. Inside the child I need to do some complicated stuff (integration test with deploying to application server and so on). So there is an integrationtest child, and from this module I need the root of the parent to reach other modules. I do not want to use "..". There is a property in integrationtest POM:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
...
</properties>
And there is an antrun plugin with the following content:
<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>
In the output, the main.basedir is not resolved:
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
After becoming really angry I decided to ask you how to get around this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道确切为什么
${project.parent.basedir}
在 AntRun 中不“可用”,也许只是不支持(参见 http://jira.codehaus.org/browse/MNG-3597)。这是使用 gmaven 的一个可怕的解决方法:
我并不为此感到自豪,但它有点“有效”(如果父 basedir 路径的字符串表示形式对你来说没问题):
但我需要说你想要什么do(从这个模块我需要父级的根才能到达其他模块)是一种不好的做法,模块应该是自包含的,而不是紧密耦合的。
我不建议使用我发布的内容:)
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:
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):
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 :)
您是否考虑过使用
maven-resources-plugin
?我必须将多模块项目中的 jacoco 生成的文件从子模块(聚合来自所有其他子模块的 jacoco 文件)复制到父目标文件夹,然后将其添加到子模块 pom.xml 时效果很好
Have you thought about using the
maven-resources-plugin
?I had to copy jacoco generated files in a multi-module project from the submodule (which aggregated the jacoco file from all other submodules) to the parent target folder and following worked nicely while adding it to the submodules pom.xml