Search code examples
grailsgradlebuild.gradlegrails-3.1

Gradle - exclude jar from dependencies only for production


I'm about to deploy my Grails 3 web-app using gradle assemble to create the war file, and I'm trying to exclude a few jar files from it.

In particular I added in my build.gradle configuration file

dependencies {
    [...]
    assets 'com.bertramlabs.plugins:sass-asset-pipeline:2.7.2'
}

These are the internal dependencies for the above plugin, which helps me to process SASS files into CSS

 \--- com.bertramlabs.plugins:sass-asset-pipeline:2.7.2
      +--- com.bertramlabs.plugins:asset-pipeline-core:2.7.2
      |    +--- org.mozilla:rhino:1.7R4
      |    +--- com.google.javascript:closure-compiler:v20151015
      |    \--- commons-logging:commons-logging:1.1.1
      +--- log4j:log4j:1.2.17
      +--- org.jruby:jruby-complete:1.7.11 -> 1.7.18
      \--- com.bertramlabs.plugins:jruby-container:0.6.1
           \--- org.jruby:jruby-complete:1.7.18

I excluded the org.ruby group as the jar is 22MB and is not needed in production as the assemble task already bundles my css resources.

configurations {
    compile.exclude group: 'org.jruby'
    [...]
}

This works for production environment but the dependency is instead needed for development.

Is there a quick way to achieve this? Thanks in advance!


Solution

  • Thanks to Arjang suggestion this solved my problem (though I'm sure there must me some other solution)

    assets ("com.bertramlabs.plugins:sass-asset-pipeline:2.7.2") {
        if(project.gradle.startParameter.taskNames.contains('assemble')) {
            exclude group: 'org.jruby'
        }
    }