Can not use different compilationLevels in the same exectuion #34

Open
martenbohlin opened this Issue Oct 18, 2012 · 7 comments

Comments

Projects
None yet
5 participants

I have two different sets of javascripts, one that I want to apply simple optimizations on and one that should have advanced optimizations. But when I invoke the target with advanced optimization (gradle projectx:minifyBJs) I get the simple optimization of the files defined for target minifyBJs. If I remove minifyAJs it works as expected.


task minifyBJs(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
    source = combineBJs
    dest = file("${buildDir}/js/b-min.js")
    closure {
        compilationLevel = 'ADVANCED_OPTIMIZATIONS'     
        externs = files("${javascriptSourceDir}/externs.js")
        warningLevel = 'QUIET'
    }
}

task minifyAJs(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
    source = combineAJs
    dest = file("${buildDir}/js/a-min.js")
    closure {
        compilationLevel = 'SIMPLE_OPTIMIZATIONS'
        warningLevel = 'QUIET'
    }
}

eriwen was assigned Oct 25, 2012

Owner

eriwen commented Oct 25, 2012

This is due to how this gradle plugin uses Extensions to configure Google Closure Compiler. The last configuration of the extension wins it seems, per project.

Therefore you might consider different subprojects with different Closure configurations, if that'll work for you.

Otherwise, we'd have the plugin to using task configuration over extensions, correct @alkemist?

Collaborator

alkemist commented Oct 25, 2012

Just checked the code. The way that extensions are being used is not quite right.

Tasks shouldn't reach out to project extensions. The MinifyJsTask needs to expose the same configuration options as the project extension. Then, we wire the corresponding configuration options of the extension to the task as a defaulting mechanism (via Convention Mapping). This means that a task will use the defaults from the project extension, unless an explicit overriding value has been set on the task.

I can make this change to the code if you want. I don't think I'd class it as a breaking change.

Owner

eriwen commented Oct 25, 2012

@alkemist I would guess this is a quick change for you, and I'd really appreciate an example to follow in the future. Please do :)

Collaborator

alkemist commented Oct 29, 2012

Hey @eriwen, I'm working on it. Just taking a bit because I'm stealing time here and there to work on it.

WIll be some time this week.

Owner

eriwen commented Oct 29, 2012

@alkemist Thanks for the update. I don't think this is urgent, and I won't be insulted/bothered if you punt this back to me because you have more important stuff.

Contributor

msgilligan commented Jun 18, 2013

I think I just got bitten by this one. (I'm using Closure to process both the debug and the minified versions of a Javascript file, so I need different settings.)

oehme commented May 21, 2015

Same goes for the requireJs tasks. I'd be willing to correct the usage of extensions for that, so you can fix it accordingly for all others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment