64

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")
    }
}
raffian
  • 31,267
  • 26
  • 103
  • 174

4 Answers4

103
  • build - dependency that is only needed by the build process
  • runtime - 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 thereof
  • compile - dependency that is needed at both compile-time and runtime. This is the most common case

There are a couple of other dependency scopes:

  • test - dependency that is only needed by the tests, e.g. a mocking/testing library
  • provided - 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
Dónal
  • 185,044
  • 174
  • 569
  • 824
  • 1
    Thanks, Don, great info, just another quick question...the convention for `build` appears to follow `"groupId:artifactId:repository or version"`, is it the same for runtime and compile as well? – raffian Jan 06 '12 at 15:15
  • yes, same convention for all scopes. I never use the `repository` - I didn't even know it existed, so in my case I specify `groupId:artifactId:version` – Dónal Jan 06 '12 at 16:22
  • We're using Artifactory to store all of our artifacts, so that's why I mentioned it...thanks again! – raffian Jan 06 '12 at 16:45
  • 2
    @RaffiM you could congigure the repo in the `repositories` section of `BuildConfig.groovy` to avoid having to configure it for each dependency – Dónal Jan 07 '12 at 14:00
5

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 and grails run-app, while compile is just the former.

John Troxel
  • 61
  • 1
  • 6
3

Starting from Grails 3, dependencies are managed by Gradle. The grails-app/conf/BuildConfig.groovy file has been replaced by the build.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.

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
1

A couple grails commands help illustrate the difference. Consider grails run-app and grails 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.

doelleri
  • 19,232
  • 5
  • 61
  • 65