Search code examples
javacssbuildantautoprefixer

Adding autoprefix-cli to ANT build


I am trying to add autoprefix-cli to my ANT build. Below is my code.

<target name="auto">
<apply executable="autoprefixer-cli.bat" verbose="true" force="true" failonerror="true">
    <arg value="-d" /> <!-- Turn on verbose -->
    <arg value="prefix" />
    <arg value="*.css" />  
</apply>
</target>

When i do a ant build, it gives me an error saying resource not specified.

BUILD FAILED
D:\tempTest\AntTestProject\build.xml:25: no resources specified

Note: I can access autoprefix-cli from command line, its installed with -g flag and also it works when i directly use it from commandline.


Solution

  • The apply task basically loops the exec task on a batch of resources (files, directories, URLs, etc). If you only want to run one command, use exec instead.

    However, you will likely also need to alter your command. From Ant's exec task documentation:

    Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.

    https://ant.apache.org/manual/Tasks/exec.html

    So instead you should have:

    <exec executable="cmd" verbose="true" force="true" failonerror="true">
        <arg value="/c" />
        <arg value="autoprefixer-cli.bat" />
        <arg value="-d" />
        <arg value="prefix" />
        <arg value="*.css" />  
    </exec>