Hi Jaikiran
I cannot reproduce the error so your sample would be really helpful,
following is my attempt to reproduce on head
without source / target, cannot be run on 1.8:
jkf@zelfbouwasuscm:~/testje$ cat build.xml
<?xml version="1.0"?>
<project name="testje" default="build" basedir=".">
<target name="build">
<javac srcdir="src" destdir="bin"/>
<!--<javac srcdir="src" destdir="bin" source="1.8" target="1.8"/>-->
</target>
</project>
jkf@zelfbouwasuscm:~/testje$ java --version
openjdk 11.0.3 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)
jkf@zelfbouwasuscm:~/testje$ ~/git-ant/ant/dist/bin/ant
Buildfile: /home/jkf/testje/build.xml
build:
[javac] /home/jkf/testje/build.xml:4: warning: 'includeantruntime'
was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Compiling 1 source file to /home/jkf/testje/bin
BUILD SUCCESSFUL
Total time: 0 seconds
jkf@zelfbouwasuscm:~/testje$ java -classpath bin Testje
Hoi
jkf@zelfbouwasuscm:~/testje$ ~/java/jdk8/bin/java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
jkf@zelfbouwasuscm:~/testje$ ~/java/jdk8/bin/java -classpath bin Testje
Error: A JNI error has occurred, please check your installation and try
again
Exception in thread "main" java.lang.UnsupportedClassVersionError:
Testje has been compiled by a more recent version of the Java Runtime
(class file version 55.0), this version of the Java Runtime only
recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Edit to have source 1.8 / target 1.8 will run with 1.8
jkf@zelfbouwasuscm:~/testje$ vi build.xml
jkf@zelfbouwasuscm:~/testje$ cat build.xml
<?xml version="1.0"?>
<project name="testje" default="build" basedir=".">
<target name="build">
<!--<javac srcdir="src" destdir="bin"/>-->
<javac srcdir="src" destdir="bin" source="1.8" target="1.8"/>
</target>
</project>
jkf@zelfbouwasuscm:~/testje$ ~/git-ant/ant/dist/bin/ant
Buildfile: /home/jkf/testje/build.xml
build:
[javac] /home/jkf/testje/build.xml:5: warning: 'includeantruntime'
was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Compiling 1 source file to /home/jkf/testje/bin
[javac] warning: [options] bootstrap class path not set in
conjunction with -source 8
[javac] 1 warning
BUILD SUCCESSFUL
Total time: 0 seconds
jkf@zelfbouwasuscm:~/testje$ ~/java/jdk8/bin/java -classpath bin Testje
Hoi
Edit to use release 8 also will run with 1.8:
jkf@zelfbouwasuscm:~/testje$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)
jkf@zelfbouwasuscm:~/testje$ vi build.xml
jkf@zelfbouwasuscm:~/testje$ cat build.xml
<?xml version="1.0"?>
<project name="testje" default="build" basedir=".">
<target name="build">
<!--<javac srcdir="src" destdir="bin"/>-->
<javac srcdir="src" destdir="bin" release="8"/>
<!--<javac srcdir="src" destdir="bin" source="1.8" target="1.8"/>-->
</target>
</project>
jkf@zelfbouwasuscm:~/testje$ ~/git-ant/ant/dist/bin/ant
Buildfile: /home/jkf/testje/build.xml
build:
[javac] /home/jkf/testje/build.xml:5: warning: 'includeantruntime'
was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Compiling 1 source file to /home/jkf/testje/bin
BUILD SUCCESSFUL
Total time: 0 seconds
jkf@zelfbouwasuscm:~/testje$ ~/java/jdk8/bin/java -classpath bin Testje
Hoi
updating the release to 9 will give the class version error (albeit with
version 53 instead of 55 which also seems correct as the target is now 9
instead of 8)
jkf@zelfbouwasuscm:~/testje$ vi build.xml
jkf@zelfbouwasuscm:~/testje$ cat build.xml
<?xml version="1.0"?>
<project name="testje" default="build" basedir=".">
<target name="build">
<!--<javac srcdir="src" destdir="bin"/>-->
<javac srcdir="src" destdir="bin" release="9"/>
<!--<javac srcdir="src" destdir="bin" source="1.8" target="1.8"/>-->
</target>
</project>
jkf@zelfbouwasuscm:~/testje$ ~/git-ant/ant/dist/bin/ant
Buildfile: /home/jkf/testje/build.xml
build:
[javac] /home/jkf/testje/build.xml:5: warning: 'includeantruntime'
was not set, defaulting to build.sysclasspath=last; set to false for
repeatable builds
[javac] Compiling 1 source file to /home/jkf/testje/bin
BUILD SUCCESSFUL
Total time: 0 seconds
jkf@zelfbouwasuscm:~/testje$ ~/java/jdk8/bin/java -classpath bin Testje
Error: A JNI error has occurred, please check your installation and try
again
Exception in thread "main" java.lang.UnsupportedClassVersionError:
Testje has been compiled by a more recent version of the Java Runtime
(class file version 53.0), this version of the Java Runtime only
recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Best Regards, Martijn
On 25-08-19 09:18, Jaikiran Pai wrote:
Hello Martijn,
I was in the process of running some tests to decide if we are in a
state to do a release of Ant project. While doing so, I ran into an
issue where our project build no longer honours the source, target and
release attributes of the javac task for versions of javac that support
it. For example when building with Java 11 our "compile" target in
build.xml although has the correct attribute values, those values never
get passed to the underlying javac call. As a result, the compiled
classes use an incorrect major/minor version and can no longer boot in
Java 8, when compiled from Java 11. Debugging this, I found that this
issue is a consequence of the changes in [1][2][3]. [2] and [3] are just
follow-up commits to [1], so the main issue seems to be related to the
change in [1]. I tried to review it, but don't have much context around
that change. Was it related to some enhancement/bug-fix? Let me know if
you need a simple reproducer to help reproduce this problem locally.
I haven't yet had a chance to see if this impacts other attributes of
the javac task and not just source/target/release attributes.
[1]
https://github.com/apache/ant/commit/8f903513877e81e1c2e180c80c467f1ad71fc1d9
[2]
https://github.com/apache/ant/commit/7b825e7c9600aa98156572bf8e83871f7e6bd911
[3]
https://github.com/apache/ant/commit/4af231688855cfc59c11e24250852158b3eeb3f8
-Jaikiran
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org