Including closure library in an existing closure compiler ant build

300 views
Skip to first unread message

Johannes Ebersold

unread,
May 21, 2012, 3:26:55 AM5/21/12
to Closure Library Discuss
Hi,

i am currently trying to integrate the closure library in an existing
closure compiler ant build system of our project.
However, i found this small example: http://code.google.com/p/closure-compiler/wiki/BuildingWithAnt
But, this example does not describe how to integrate the closure
library. After some searching and reading i found the
"use_closure_library" option, which is, unfortunately, for the service
API.

Is there a way to include the closure library easily in the ant
script, maybe using such a simple flag?

Here is the part of my ant where the compiler stuff happens, externs
and sourceFiles are lists that are defined elsewhere ... :
<macrodef name="compileScripts">
<attribute name="extension" default="-min" />
<attribute name="level" default="simple" />
<attribute name="version" />
<element name="args" optional="true" />
<sequential>
<jscomp compilationlevel="@{level}" warning="verbose"
generateexports="yes" debug="false"
output="${buildDir}/${script.start}@{extension}.js">
<args/>
<externs refid="externs">
</externs>
<sources refid="sourceFiles">
</sources>
</jscomp>
</sequential>
</macrodef>

I did not work much with ant scripts, so i am a bit lost at that point
and would really appreciate any help.

Cheers, Johannes

Dave Fisher

unread,
May 22, 2012, 11:45:08 AM5/22/12
to closure-lib...@googlegroups.com
Yeah there are a lot of different ways to use Ant do to a build. The recommended mechanism is to use the closurebuilder.py module. Then including the library is just a matter of listing it as a root. Here is information on closurebuilder.py: https://developers.google.com/closure/library/docs/closurebuilder

Then using the closurebuilder.py module is not too bad with Ant. I'm not sure if this will help or not, but here is a build file I was using once.

<!-- Set based on your folder structure -->
<property name="closure.dir" value="${basedir}/../../../closure" />
<!-- My folder structure within the closure folder:
closure/closure-compiler (svn checkout of http://closure-compiler.googlecode.com/svn/trunk/)
closure/closure-library (svn checkout of http://closure-library.googlecode.com/svn/trunk/)
closure/closure-templates (svn checkout of http://closure-templates.googlecode.com/svn/trunk/) -->

<property name="closure-library.dir" value="${closure.dir}/closure-library" />
<property name="compiler.jar" value="${closure.dir}/closure-compiler/build/compiler.jar" />

<macrodef name="closure-builder">
    <attribute name="root" />
<element name="namespaces" optional="no"/>
    <attribute name="outputfile" />
    <attribute name="compilationlevel" default="ADVANCED_OPTIMIZATIONS" />
    <element name="extraflags" optional="yes"/>
    <sequential>
      <exec executable="python" failonerror="true" logError="true">
        <arg value="${closure-library.dir}/closure/bin/build/closurebuilder.py" />
        <arg line='--root="${closure-library.dir}"' />
        <arg line='--root="@{root}"' />
        <namespaces />
        <arg line='--output_mode=compiled' />
        <arg line='--compiler_jar=${compiler.jar}' />
        <arg line='--output_file=@{outputfile}' />
        <arg line='--compiler_flags="--compilation_level=@{compilationlevel}"' />
        <arg line='--compiler_flags="--js=${closure-library.dir}/closure/goog/deps.js"' />
        <arg line='--compiler_flags="--warning_level=VERBOSE"' />
        <extraflags />
      </exec>
    </sequential>
  </macrodef>



<target name="my-target" description="generates myJavaScript.js">
<closure-builder
      root='${basedir}/js/'
      outputfile="${build.dir}/files/myJavaScript.js"
       compilationlevel="ADVANCED_OPTIMIZATIONS" >
<namespaces>        
<arg line='--namespace=mynamespace.Main' />
      </namespaces>
      <extraflags>
       <!-- Optional. This turns what would be warnings into errors for type safety. -->
        <arg line='--compiler_flags="--jscomp_error=checkTypes"' />
      </extraflags>
    </closure-builder>
  </target>
Reply all
Reply to author
Forward
0 new messages