【问题标题】:Can Maven convert comma separated list of files into multiple <file> elements?Maven 可以将逗号分隔的文件列表转换为多个 <file> 元素吗?
【发布时间】:2016-04-20 05:38:24
【问题描述】:

Maven 可以将逗号分隔的文件列表转换为多个&lt;file&gt; 元素吗?我想将一个 arg 传递给包含多个文件的套件,如下所示:

-DngFiles=testng1.xml,testng2.xml

我找到了一个定义多个套件文件的插件示例。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <suiteXmlFiles>
      <file>src/test/resources/testng1.xml</file>
      <file>src/test/resources/testng2.xml</file>
    </suiteXmlFiles>
  </configuration>
</plugin>

我希望,鉴于上述情况,这样的事情可能是可能的?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <suiteXmlFiles>
      <files>${ngFiles}</files>
    </suiteXmlFiles>
  </configuration>
</plugin>

在我看来,除了修改 Surefire 插件本身的行为之外,可能没有其他方法可以做到这一点,对吧?没有 Maven 插件可以做我想做的事吗?

【问题讨论】:

    标签: maven


    【解决方案1】:

    Generally speaking, Maven can't do this automatically。插件是否支持这样的配置。

    在这种情况下,suiteXmlFiles 具有相应的用户属性,即surefire.suiteXmlFiles。这意味着,在命令行中,您可以直接将其设置为多个以逗号分隔的值:

    -Dsurefire.suiteXmlFiles=src/test/resources/testng1.xml,src/test/resources/testng2.xml
    

    这意味着您实际上不需要为maven-surefire-plugin 定义任何配置。您只需要确保使用最新的 2.19.1 版本:

    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19.1</version>
    </plugin>
    

    通常,插件中列表的两种配置类型是:

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多