eriwen / gradle-js-plugin

Gradle plugin for working with JS
http://eriwen.github.io/gradle-js-plugin
Apache License 2.0
382 stars 113 forks source link

2 MinifyJsTask tasks with different configurations produce same output file #128

Open Eluckye opened 8 years ago

Eluckye commented 8 years ago

I have a js file and I want to have 2 more.

  1. A debug version file.
  2. A minified version file.

So, I created two tasks willing to achieve this:

//Debug version, which removes comments
task debug_version(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {

    def options = new com.google.javascript.jscomp.CompilerOptions()
    options.setPrettyPrint(true)

     source = file("${buildDir}/input.js")
     dest = file("${buildDir}/debug.js")
     closure {
        compilationLevel = 'WHITESPACE_ONLY'
        warningLevel = 'QUIET'
        compilerOptions = options
     }
}
//Minified Version, compresses and variables renamed
task minified_version(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {

    def x = new com.google.javascript.jscomp.CompilerOptions()
    x.setPrettyPrint(false)

    source = file("${buildDir}/input.js")
    dest = file("${buildDir}/minified.js")
    closure {
        compilationLevel = 'SIMPLE_OPTIMIZATIONS'
        warningLevel = 'QUIET'
        compilerOptions = x
    }
}

Then, if I run any of the above tasks, they will produce a output file with the same content (and different name: minified.js or debug.js), which will be the "Minified" version. It seems that all the MinifyJsTask tasks will keep the configuration of the task which is at the very bottom. I know this because when I removed minified_version task, I was able to run debug_version task and I obtained the debug file that I want to obtain running this task.

Is this supposed to work like this? Am I doing it in a wrong way? Do you have any suggestions?

spn commented 8 years ago

sound like the same issue addressed by the pull request https://github.com/eriwen/gradle-js-plugin/pull/127