【问题标题】:Grails BuildConfig.groovy, difference between build, compile, and runtime?Grails BuildConfig.groovy,构建、编译和运行时的区别?
【发布时间】:2012-02-03 19:24:59
【问题描述】:

buildruntimecompile 之间有什么区别,在 BuildConfig.groovy (1.3.7) 中

grails.project.dependency.resolution = {

    plugins {
        build "acme:acme-cache:latest.integration"
    }

    dependencies {
        build "com.foo.bar:foobar:1.0.5"       
        runtime "org.apache.httpcomponents:httpclient:4.0.3"
        compile("com.thoughtworks.xstream:xstream:1.3.1")
    }
}

【问题讨论】:

    标签: grails build compilation config


    【解决方案1】:
    • build - 只有构建过程才需要的依赖项
    • runtime - 运行应用程序所需的依赖项,但不编译它,例如特定数据库供应商的 JDBC 实现。这通常在编译时不需要,因为代码仅依赖于 JDBC API,而不是其特定实现
    • compile - 编译时和运行时都需要的依赖项。这是最常见的情况

    还有几个其他的依赖范围:

    • test - 仅测试需要的依赖项,例如一个模拟/测试库
    • provided - 编译时需要但不应与应用程序打包的依赖项(通常是因为它是由容器提供的)。一个例子是 Servlet API

    【讨论】:

    • 谢谢,Don,很棒的信息,只是另一个简单的问题...build 的约定似乎遵循"groupId:artifactId:repository or version",运行时和编译是否也一样?
    • 是的,所有范围的约定相同。我从不使用repository - 我什至不知道它的存在,所以在我的情况下我指定groupId:artifactId:version
    • 我们使用 Artifactory 来存储我们所有的工件,所以这就是我提到它的原因......再次感谢!
    • @RaffiM 您可以在BuildConfig.groovyrepositories 部分配置repo,以避免必须为每个依赖项配置它
    【解决方案2】:

    似乎前两个答案在编译和构建之间的区别上存在冲突。我认为build是包含grails compilegrails run-app的范围,而compile只是前者。

    【讨论】:

      【解决方案3】:

      从 Grails 3 开始,依赖项由 Gradle 管理。 grails-app/conf/BuildConfig.groovy 文件 has been replaced 由项目根目录中的 build.gradle 文件组成。

      Grails 用户指南explain how to set grails depencies with gradle 并参考related Gradle documentation 以了解有关此主题的更多详细信息。

      【讨论】:

        【解决方案4】:

        几个 grails 命令有助于说明差异。考虑grails run-appgrails compilegrails compile 是编译步骤,将包括编译时依赖项。 grails run-app 是运行步骤,将包括运行时依赖项。构建依赖项是运行任何这些命令可能需要的任何东西,例如,挂钩到某些构建事件的自定义脚本。

        因此,当您需要确定包含依赖项时,您会选择最适合的那个。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-09
          • 2013-05-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多