Skip to content

Instantly share code, notes, and snippets.

@niloc132
Created April 14, 2022 19:47
Show Gist options
  • Save niloc132/1244ad7b72ec951800c5c1c12bfe08bc to your computer and use it in GitHub Desktop.
Save niloc132/1244ad7b72ec951800c5c1c12bfe08bc to your computer and use it in GitHub Desktop.
Sample project to use when testing closure releases to ensure that shaded and unshaded projects build properly. Enable either closure-compiler or closure-compiler-unshaded, then run mvn package, confirm that both stages run, and output is created.
// input file to test with, named in the pom.xml
var hello = "world";
window.alert("Hello, " + hello + "!");
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>try-closure-jars</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- Toggle these two, only enabling one at a time -->
<dependency>
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler-unshaded</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.google.javascript</groupId>-->
<!-- <artifactId>closure-compiler</artifactId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>stage1</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.javascript.jscomp.CommandLineRunner</argument>
<argument>--compilation_level=ADVANCED</argument>
<argument>--save_stage1_to_file=output.typedast</argument>
<argument>--js=${project.basedir}/file.js</argument>
<argument>--js_output_file=out.js</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>stage2</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.javascript.jscomp.CommandLineRunner</argument>
<argument>--compilation_level=ADVANCED</argument>
<argument>--restore_stage1_from_file=output.typedast</argument>
<argument>--js=${project.basedir}/file.js</argument>
<argument>--js_output_file=out.js</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment