2011-08-04 21 views
1

我想为我们的项目编写一个集成测试POM。我们已经下载并安装/解压缩了项目(使用maven-dependency-plugin),但是我们项目的一个警告是,它还不能在其中包含空格的路径中运行。我正在寻找一种评估$ {project.build.directory}的非常简单的方法,如果它包含空格,就会抛出一个人类可读的错误。我希望在下载依赖之前发生这种情况,因为这需要相当长的时间。如何测试路径中的空间并给出适当的错误?

回答

2

这将在antrun插件和<contains>条件的帮助下完成。

<build> 
    <plugins>      
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.6</version> 
     <executions> 
     <execution> 
      <phase>validate</phase> 
      <goals> 
      <goal>run</goal> 
      </goals> 
      <configuration> 
      <target> 
       <fail message="project.build.directory(${project.build.directory}) contains spaces"> 
       <condition> 
        <contains string="${project.build.directory}" substring=" "/> 
       </condition> 
       </fail> 
      </target> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 
+0

我已经告诉我的maven-philes避免antrun插件像瘟疫......任何其他的想法? – Jared

+0

@Jared。你可以写20多行,为'maven-enforcer-plugin'创建一个自定义规则。 http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html。顺便说一句,反对antrun的是什么?在我看来,这是适合正确目的的正确工具。 –

+0

我个人对antrun插件没有异议,但是有些人(包括我公司的人)想要尽可能地避免使用它,因为它经常被用于破解非maven-esque办法。如果没有人提出另一种方式,我会将您的答案标记为已接受的答案。 – Jared

相关问题