ant warning: "'includeantruntime' was not set"

260,881

Solution 1

Ant Runtime

Simply set includeantruntime="false":

<javac includeantruntime="false" ...>...</javac>

If you have to use the javac-task multiple times you might want to consider using PreSetDef to define your own javac-task that always sets includeantruntime="false".

Additional Details

From http://www.coderanch.com/t/503097/tools/warning-includeantruntime-was-not-set:

That's caused by a misfeature introduced in Ant 1.8. Just add an attribute of that name to the javac task, set it to false, and forget it ever happened.

From http://ant.apache.org/manual/Tasks/javac.html:

Whether to include the Ant run-time libraries in the classpath; defaults to yes, unless build.sysclasspath is set. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run.

Solution 2

As @Daniel Kutik mentioned, presetdef is a good option. Especially if one is working on a project with many build.xml files which one cannot, or prefers not to, edit (e.g., those from third-parties.)

To use presetdef, add these lines in your top-level build.xml file:

  <presetdef name="javac">
    <javac includeantruntime="false" />
  </presetdef>

Now all subsequent javac tasks will essentially inherit includeantruntime="false". If your projects do actually need ant runtime libraries, you can either add them explicitly to your build files OR set includeantruntime="true". The latter will also get rid of warnings.

Subsequent javac tasks can still explicitly change this if desired, for example:

<javac destdir="out" includeantruntime="true">
  <src path="foo.java" />
  <src path="bar.java" />
</javac>

I'd recommend against using ANT_OPTS. It works, but it defeats the purpose of the warning. The warning tells one that one's build might behave differently on another system. Using ANT_OPTS makes this even more likely because now every system needs to use ANT_OPTS in the same way. Also, ANT_OPTS will apply globally, suppressing warnings willy-nilly in all your projects

Solution 3

Chet Hosey wrote a nice explanation here:

Historically, Ant always included its own runtime in the classpath made available to the javac task. So any libraries included with Ant, and any libraries available to ant, are automatically in your build's classpath whether you like it or not.

It was decided that this probably wasn't what most people wanted. So now there's an option for it.

If you choose "true" (for includeantruntime), then at least you know that your build classpath will include the Ant runtime. If you choose "false" then you are accepting the fact that the build behavior will change between older versions and 1.8+.

As annoyed as you are to see this warning, you'd be even less happy if your builds broke entirely. Keeping this default behavior allows unmodified build files to work consistently between versions of Ant.

Solution 4

The answer from Daniel works just perfect. Here is a sample snippet that I added to my build.xml:

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
                                                 <!--   ^^^^^^^^^^^^^^^^^^^^^^^^^  -->
        <classpath>
            <path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
            <path id="junit" location="${lib.dir}/junit-4.9b2.jar"/>
        </classpath>
    </javac>
</target>

Solution 5

Use <property name="build.sysclasspath" value="last"/> in your build.xml file

For more details search includeAntRuntime in Ant javac

Other possible values could be found here

Share:
260,881
user496949
Author by

user496949

Updated on July 08, 2022

Comments

  • user496949
    user496949 almost 2 years

    I receive the following warning:

    [javac] build.xml:9: warning: 'includeantruntime' was not set, 
    defaulting to build.sysclasspath=last; set to false for repeatable builds
    

    What does this mean?

  • user496949
    user496949 about 13 years
    Apache Ant(TM) version 1.8.2 compiled on December 20 2010
  • Daniel Kutik
    Daniel Kutik about 13 years
    so if you need the ant runtime in the classpath set it to yes/true otherwise to no/false. i guess you don't need it.
  • Jonik
    Jonik almost 13 years
    +1, Great answer. I just wish I could set that once somewhere in the buildfile instead of littering every javac call with it...
  • karmakaze
    karmakaze about 12 years
    I always thought this was the most silly feature/message ever. Who wants 'repeatable builds' in their configuration management tool? ;)
  • saxman
    saxman almost 12 years
    Works great for retrofitting an existing Ant build file with multiple javac tasks. The presetdef element goes just inside project element.
  • Stuart Golodetz
    Stuart Golodetz over 11 years
    @jwfearn: Can a similar presetdef trick be made to work for non-built-in Ant tasks? I've tried this with scalac, but because lower-down build.xml files have to manually define the scalac task, they override whatever I set at the top-level.
  • mikijov
    mikijov over 11 years
    A note, that using presetdef will cause an ant warning that javac task has been redefined. Addind includeantruntime to each javac task avoids this. I am not aware of downsides of the warning. But this might be useful for people who 'need' clean builds.
  • mike jones
    mike jones over 11 years
    Yes the presetdef gives "Trying to override old definition of task javac"
  • Paul Vargas
    Paul Vargas almost 8 years
    This helps me a lot. I'm using set ANT_OPTS=-Xms40M -Xmx512M -Dbuild.sysclasspath=ignore.
  • Lorenzo Lerate
    Lorenzo Lerate over 7 years
    What does it any case it is set to True?
  • Daniel Kutik
    Daniel Kutik over 7 years
    "Whether to include the Ant run-time libraries in the classpath; defaults to yes, unless build.sysclasspath is set. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run."
  • t.y
    t.y about 6 years
    This answer seems to be the only one that tells us what the warning actually means.
  • deepakl.2000
    deepakl.2000 almost 2 years
    Im facing an ant issue