【问题标题】:How do I add a JAR to the classpath of a Grails project only for test scope?如何将 JAR 添加到 Grails 项目的类路径中,仅用于测试范围?
【发布时间】:2013-11-14 13:45:55
【问题描述】:

通常,我会在 BuildConfig.groovy 中为测试范围声明一个测试依赖项,并且知道它只会在类路径中进行测试,并且不会打包到已部署的应用程序中:

test "org.seleniumhq.selenium:selenium-htmlunit-driver:2.27.0"

我想在测试时包含另一个 JAR,但它在 maven 存储库中不可用,因此我无法像往常一样声明依赖项。

如何将 JAR 添加到我的项目中,将其签入,但声明它仅在测试时可用?

我目前正在使用 Grails 2.1.1,但将来会使用 2.3.x。

谢谢。

【问题讨论】:

    标签: grails testing dependencies


    【解决方案1】:

    我很确定 lib 文件夹中的所有 jar 都是编译范围的,因此您无法将其更改为测试。

    您可以做的是在构建过程中排除它们,使用 BuildConfig.groovy 中的配置 grails.war.resources

    // Remove the JDBC jar before the war is bundled
    grails.war.resources = { stagingDir ->
      delete(file:"${stagingDir}/WEB-INF/lib/jdbc2_0-stdext.jar")
    }
    

    这取自Palmer's post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 2016-11-04
      • 2010-11-23
      • 2010-12-03
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多