pukkaone/closure-compiler-maven-plugin


Maven plugin for compiling JavaScript with Google Closure Compiler

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.pukkaone:closure-compiler-maven-plugin:1.0.0'
	}
	dependencies {
		implementation("com.github.pukkaone:closure-compiler-maven-plugin:1.0.0")
	}
	<dependency>
	    <groupId>com.github.pukkaone</groupId>
	    <artifactId>closure-compiler-maven-plugin</artifactId>
	    <version>1.0.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.pukkaone" % "closure-compiler-maven-plugin" % "1.0.0"
        
        

                            
    :dependencies [[com.github.pukkaone/closure-compiler-maven-plugin "1.0.0"]]
        
        

Readme


Google Closure Compiler Maven Plugin

This project is forked from https://github.com/gli/closure-compiler-maven-plugin to implement additional features.

Entry point configuration

Configure the plugin to include only transitive dependencies of specified entry points.

<entryPoints>
  <entryPoint>application.Main</entryPoint>
</entryPoints>

goog.require returns namespace

Patched Closure Compiler so goog.require can appear inside goog.scope, and goog.require returns the namespace so you can assign it to a variable. For example:

goog.provide('some.Example');

goog.scope(function() {
  var Vec2 = goog.require('goog.math.Vec2');

  some.Example = function() {
    console.log(new Vec2());
  };
});

See https://code.google.com/p/closure-compiler/issues/detail?id=674

Configure Your Maven Project To Use Plugin

<properties>
  <closure.source>src/main/js</closure.source>
  <closure.externs>src/main/externs</closure.externs>
  <closure.outputFile>${project.build.directory}/compiled.js</closure.outputFile>
</properties>

<build>
  <plugins>
    <!-- ... -->

    <plugin>
      <groupId>com.github.pukkaone</groupId>
      <artifactId>closure-compiler-maven-plugin</artifactId>
      <version>1.0.0</version>
      <executions>
        <execution>
          <phase>process-resources</phase>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <sourceDirectory>${closure.source}</sourceDirectory>
        <externsSourceDirectory>${closure.externs}</externsSourceDirectory>
        <entryPoints>
          <entryPoint>application.Main</entryPoint>
        </entryPoints>
        <outputFile>${closure.outputFile}</outputFile>
        <compilationLevel>SIMPLE_OPTIMIZATIONS</compilationLevel>
        <merge>true</merge>
        <loggingLevel>WARNING</loggingLevel>
        <warningLevel>VERBOSE</warningLevel>
        <generateExports>true</generateExports>
        <addDefaultExterns>true</addDefaultExterns>
        <logExternFiles>true</logExternFiles>
        <logSourceFiles>true</logSourceFiles>
        <stopOnErrors>true</stopOnErrors>
        <stopOnWarnings>true</stopOnWarnings>
      </configuration>
    </plugin>

    <!-- ... -->
  </plugins>
</build>