如何在没有测试范围罐的情况下进行maven安装

时间:2015-07-17 11:48:24

标签: java maven heroku

该应用程序是用Java编写的,并且正在Heroku上运行。我不希望在生产环境中使用带有测试范围的罐子。其中一个原因是Heroku-slug的大小。因此,例如junit,selenium和绿色邮件罐目前在目标/依赖目录中,我宁愿他们不是。

我可以用pom或maven选项来阻止maven将测试范围的jar放入目标/依赖吗?

我已经有几个解决方案要求我维护第二个不包含的文件列表。但手动同步两个列表有一个很快就会失败的倾向。

2 个答案:

答案 0 :(得分:1)

我相信您需要将<includeScope>compile</includeScope>添加到您的maven-dependency-plugin配置中:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.4</version>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <phase>package</phase>
      <goals><goal>copy-dependencies</goal></goals>
      <configuration>
        <includeScope>compile</includeScope>
      </configuration>
    </execution>
  </executions>
</plugin>

包含的范围默认为test,其中包括您的测试依赖项,因此compile实际上会将它们排除在外。

答案 1 :(得分:0)

是的,有一种方法,您可以限制依赖的范围仅用于测试。 只需在 prod 环境中定义您不想要的每个依赖项的scope,如下所示,并带有<scope></scope>标记。

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>