Google Closure using ES5 strict mode even though I specified non-strict mode (in minify-maven-plugin configuration)

1.3k views Asked by At

I'm using the com.samaxes.maven minify-maven-plugin to minify a collection of JS source files written using some of the ES6 features Google Closure supports. Here's the relevant configuration in my POM:

<!-- minify-maven-plugin: Minification using Google Closure -->
<plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>minify-maven-plugin</artifactId>
    <version>1.7.6</version>
    <executions>
        <!-- Creation of the common-[version].js file -->
        <execution>
            <id>common-minify</id>
            <phase>prepare-package</phase>
            <configuration>
                <charset>UTF-8</charset>
                <jsSourceDir>.</jsSourceDir>
                <jsSourceFiles>
                    ...
                </jsSourceFiles>
                <jsFinalFile>./js/common-${project.version}.js</jsFinalFile>
                <jsEngine>CLOSURE</jsEngine>
                <closureLanguageIn>ECMASCRIPT6</closureLanguageIn>
                <closureLanguageOut>ECMASCRIPT5</closureLanguageOut>
            </configuration>
            <goals>
                <goal>minify</goal>
            </goals>
        </execution>

        <!-- 2 other similarly configured executions are here. -->
        ...

    </executions>
</plugin>

The problem is, when I run the maven goal this configuration, I get the following error message:

[INFO] Creating the merged file [common-1.8.24.js].
[INFO] Creating the minified file [common-1.8.24.min.js].
Jan 03, 2017 12:03:06 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: [1mcommon-1.8.24.js:5577: [31mERROR[39m - object literals cannot contain duplicate keys in ES5 strict mode[0m
    supportsDataForwarding: function () {
    ^ 

This looks to me like Google Closure is trying to compile using ES5 Strict mode, even though I specified the non-strict ECMASCRIPT5 mode in my <closureLanguageOut> option (see doc here). Why is it not disabling strict mode?

1

There are 1 answers

0
Sebastian Häger On BEST ANSWER

i had the same problem and found a way to let the minify-maven-plugin not fail the build in case it complains about ES5 strict mode:

<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
    <execution>
        <id>default-minify</id>
        <phase>process-resources</phase>
        <configuration>
            <charset>UTF-8</charset>                
            <closureWarningLevels>
                <es5Strict>OFF</es5Strict>
            </closureWarningLevels>
            ...
        </configuration>
        <goals>
            <goal>minify</goal>
        </goals>
    </execution>
</executions>

You may further fine-tune using the following documentation How to tell closure compiler which warnings you want. Hope this helps :)