Last Updated: February 25, 2016
·
1.656K
· mdrmtz

Compile Less to css using Ant

build.common.properties

rhino.dir    = /tools/java-libs/rhino-1.7R4
htdocs.css.dir   = /htdocs/angular/app/styles
htdocs.less.dir     = /htdocs/angular/bower_components/less

build.xml

<property file="build.common.properties"/>
<!-- compile all (css) LESS files in a dir and subdirs with RHINO -->
  <property name="css.dir" location="${htdocs.css.dir}"/>
  <property name="tool.less"  location="${htdocs.less.dir}/dist/less-rhino-1.7.4.js"/>
  <property name="tool.lessc" location="${htdocs.less.dir}/dist/lessc-rhino-1.7.4.js"/>
  <property name="tool.rhino" location="${rhino.dir}/js.jar"/>


<target name="less" description="Convert LESS to CSS then concatenate and Minify any stylesheets">

      <echo message="Converting LESS to CSS..."/>
      <!-- Clear the former compiled css files -->
          <delete includeemptydirs="true">
                <fileset dir="${css.dir}" includes="*.css, **/*.css" defaultexcludes="false"/>
          </delete>

          <apply dir="${css.dir}" executable="java" parallel="false" failonerror="true" verbose="true">
      <!-- Give the input bundle of less files-->
              <fileset dir="${css.dir}">
                  <include name="*.less"/>
              </fileset>
              <arg value="-jar" />     
              <arg path="${tool.rhino}" />
              <arg value="-f" />
              <arg path="${tool.less}" />
              <arg path="${tool.lessc}" />
              <arg value="-x" />
              <srcfile/>
      <!-- Output the compiled css file with corresponding name -->
              <mapper type="glob" from="*.less" to="${css.dir}/*.css"/>
              <targetfile/>
          </apply>

  </target>

Console

ant less