里面的maven antrun插件父属性
-
27-09-2019 - |
题
有是一个多模块项目。孩子里面我需要做一些复杂的东西(集成测试与部署应用服务器等)。因此,有一个孩子integrationtest,从这个模块,我需要家长的根源,达到其他模块。我不想用“..”。有在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
变得非常生气后我决定问你该怎么解决这个问题?
解决方案
我不知道的究竟的为什么${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 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 ...
但我需要说你想要做什么(从这个模块,我需要家长的根源,达到其他模块的)是坏习惯,模块应该是自包含的,不紧密耦合的。
我不建议使用的是什么我张贴:)
不隶属于 StackOverflow