ChatGPT解决这个技术问题 Extra ChatGPT

ant warning: "'includeantruntime' was not set"

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?


D
Daniel Kutik

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.


Apache Ant(TM) version 1.8.2 compiled on December 20 2010
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.
+1, Great answer. I just wish I could set that once somewhere in the buildfile instead of littering every javac call with it...
What does it any case it is set to True?
"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."
j
jwfearn

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


Works great for retrofitting an existing Ant build file with multiple javac tasks. The presetdef element goes just inside project element.
@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.
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.
Yes the presetdef gives "Trying to override old definition of task javac"
C
Community

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.


I always thought this was the most silly feature/message ever. Who wants 'repeatable builds' in their configuration management tool? ;)
This answer seems to be the only one that tells us what the warning actually means.
M
Marnen Laibow-Koser

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>

s
slott

If you like me work from commandline the quick answer is executing

export ANT_OPTS=-Dbuild.sysclasspath=ignore

And then run your ant script again.


This helps me a lot. I'm using set ANT_OPTS=-Xms40M -Xmx512M -Dbuild.sysclasspath=ignore.
Im facing an ant issue
A
Ahmad Nadeem

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


G
Garun Kumar Mishra

i faced this same, i check in in program and feature. there was an update has install for jdk1.8 which is not compatible with my old setting(jdk1.6.0) for ant in eclipse. I install that update. right now, my ant project is build success.

Try it, hope this will be helpful.