【问题标题】:Gradle grails - how to exclude dependency based on environment?Gradle grails - 如何根据环境排除依赖关系?
【发布时间】:2014-11-24 10:07:38
【问题描述】:

我有一个项目,我想为某些环境包含控制台插件,但不包含其他环境 - 它应该放在(自定义)deployTest 环境中,但不适用于生产环境。

如果我使用 grails 构建应用程序,我的 BuildConfig.groovy 如下所示:

grails.project.dependency.resolution = {

/// some stuff

plugins {
    /// more dependencies       

        if (Environment.current != Environment.PRODUCTION){
            compile ":console:1.5.1"
        }


    }
}

使用 Gradle 构建 Grails 时的依赖解析基于 build.gradle 文件,而不是 BuildConfig.groovy。

请问我该如何实现?

【问题讨论】:

    标签: grails gradle dependency-management environment


    【解决方案1】:

    在我看来,您更想包含基于环境的依赖项。但是,无论哪种方式,方法都是相同的。在您的 build.gradle 文件中,您有一个“依赖项”部分。因为这是 Groovy,所以它是代码。 gradle 使用 -PgrailsEnv 值来指定环境。只需使用它:

    dependencies {
        // if no property, then gradle will be default to prod.  So test
        //   for that or having it explicitly provided
        if (!project.hasProperty('grailsEnv') || project.grailsEnv.equals('prod')) {
             compile ':console:1.5.1'
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      相关资源
      最近更新 更多