Grails BuildConfig.groovy,构建、编译和运行时之间的区别?
BuildConfig.groovy
中的 build
、runtime
和 compile
之间有什么区别 (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")
}
}
What's the difference between build
, runtime
, and compile
, in 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")
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
build
- 仅构建过程需要的依赖项runtime
- 运行应用程序所需的依赖项,但不编译它,例如特定数据库供应商的 JDBC 实现。这在编译时通常不需要,因为代码仅依赖于 JDBC API,而不是还有其他一些依赖范围:
test
- 仅测试需要的依赖项,例如模拟/测试库provided
- 依赖项在编译时需要,但不应与应用程序一起打包(通常因为它是由容器提供的)。 Servlet API 就是一个例子build
- dependency that is only needed by the build processruntime
- dependency that is needed to run the application, but not compile it e.g. JDBC implementation for specific database vendor. This would not typically be needed at compile-time because code depends only the JDBC API, rather than a specific implementation thereofcompile
- dependency that is needed at both compile-time and runtime. This is the most common caseThere are a couple of other dependency scopes:
test
- dependency that is only needed by the tests, e.g. a mocking/testing libraryprovided
- dependency that is needed at compile-time but should not be packaged with the app (usually because it is provided by the container). An example is the Servlet API似乎之前的两个答案在编译和构建之间的区别上存在冲突。我认为 build 的范围包括
grailscompile
和grailsrun-app
,而compile只是前者。It seems the 2 previous answers conflict on the distinction between compile and build. I believe that build is the scope that includes
grails compile
andgrails run-app
, while compile is just the former.从 Grails 3 开始,依赖项由 Gradle 管理。
grails-app/conf/BuildConfig.groovy
文件 已被项目根目录中的build.gradle
文件替换。Grails 用户指南解释如何使用 gradle 设置 grails 依赖。另请参阅相关 Gradle 文档,了解有关使用 Gradle 管理依赖项的更多详细信息。
Starting from Grails 3, dependencies are managed by Gradle. The
grails-app/conf/BuildConfig.groovy
file has been replaced by thebuild.gradle
file in the project's root.The Grails user guide explain how to set grails depencies with gradle. See also the related Gradle documentation for further details on managing dependencies using it.
几个 grails 命令有助于说明其中的差异。考虑
grails run-app
和grailscompile
。 grailscompile 是编译步骤,将包含编译时依赖项。 grails run-app 是运行步骤,将包含运行时依赖项。构建依赖项是运行任何这些命令可能需要的任何内容,例如,挂钩某些构建事件的自定义脚本。因此,当您需要确定包含依赖项时,您会选择最适合的一个。
A couple grails commands help illustrate the difference. Consider
grails run-app
andgrails compile
.grails compile
is the compile step and will include compile-time dependencies.grails run-app
is the run step and will include runtime dependencies. Build dependencies are anything that you might need to run any of these commands, for example, a custom script that hooks into some build events.So you would pick the one that best fits when you need to be certain the dependency is included.