0

1) I finally managed to get something compiled through Google Closure Compiler using Ant to automate the process. The problem im facing, is that all the examples provided concatenate the output into one main file (main example I followed), say foo.min.js. What I need is to minify/compile ALL the .js files in one and/or more directories into their respective .min.js files, without concatenating the output, so, lets say, I have 3 .js files, I need 3 minified .min.js outputs.

Here's my (first) current build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" basedir="." default="compile">
    <property environment="env."/>
    <property name="env.CLASSPATH" value=""/>
    <fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
        <condition>
            <not>
                <equals arg1="${env.CLASSPATH}" arg2=""/>
            </not>
        </condition>
    </fail>
    <taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="${env.CLOSURE_COMPILER}/compiler.jar" />
    <target name="compile">
        <jscomp compilationLevel="simple" warning="quiet" debug="false" output="${basedir}/admin/js/foo.min.js">
            <sources dir="${basedir}/admin/js">
                <file name="home.js" />
                <file name="mailing.js" />
                <file name="table_modal_events.js" />
            </sources>
        </jscomp>
    </target>
</project>

2) Following Ant's installation manual, I've added this

<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
    <condition>
        <not>
            <equals arg1="${env.CLASSPATH}" arg2=""/>
        </not>
    </condition>
</fail>

to the top of my project, and after building successfully multiple times this way, I noticed that if I remove <property environment="env."/> I get a taskdef class com.google.javascript.jscomp.ant.CompileTask cannot be found using the classloader AntClassLoader[] error. May I ask why? (being %CLOSURE_COMPILER% an environment variable which I also added to PATH) This answer may be related to this? But I still don't understand.

3) This is the closest related question/answer I could find. But it makes use of a bash script, so my question is: is it possible to achieve what I want using Ant?

I would appreciate if somebody could tell me what I'm doing wrong.

Community
  • 1
  • 1
n3hl
  • 87
  • 1
  • 12

1 Answers1

0

You just need something like into your target

<apply executable="java" parallel="false">
                        <fileset dir="webapp/js" includes="**/*.js" 
 excludes="any to exclude" />
                        <arg line="-jar"/>
                        <arg path="PATH/closure-compiler-XXX.jar"/>
                        <arg line="--js "/>
                        <srcfile/>
                        <arg line="--warning_level=QUIET" />
                        <arg line="--js_output_file"/>
                        <mapper type="glob" from="*.js" to="build/webapp/js/*.js"/>
                        <targetfile/>
</apply>
Arturo Bernal
  • 31
  • 1
  • 1