Grails BuildConfig.groovy, difference between build, compile, and runtime?

GrailsBuildCompilationConfig

Grails Problem Overview


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")
    }
}

Grails Solutions


Solution 1 - Grails

  • 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

Solution 2 - Grails

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.

Solution 3 - Grails

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 and refers to the related Gradle documentation for more details about this topic.

Solution 4 - Grails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionraffianView Question on Stackoverflow
Solution 1 - GrailsDónalView Answer on Stackoverflow
Solution 2 - GrailsJohn TroxelView Answer on Stackoverflow
Solution 3 - GrailslifeisfooView Answer on Stackoverflow
Solution 4 - GrailsdoelleriView Answer on Stackoverflow