Bug 67538 - Make use of Ant's <javaversion /> task to enfore the mininum Java build version
Summary: Make use of Ant's <javaversion /> task to enfore the mininum Java build version
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 11
Classification: Unclassified
Component: Documentation (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement (vote)
Target Milestone: -------
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-28 12:32 UTC by Michael Osipov
Modified: 2023-10-12 14:52 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Osipov 2023-09-28 12:32:26 UTC
This applies to 9 through 11.

Use https://ant.apache.org/manual/Tasks/conditions.html#javaversion to fail the build explicitly if the Java buld time version is not met just like done with ant.version.required. 8.5.x is out of scope since Ant 1.9 does not support this task.

When you build only once in a while you simply forget to switch to the required Java version and see obscure error messages. This we can do better with this task.
Comment 1 Konstantin Kolinko 2023-09-28 13:41:35 UTC
It is supported in Ant 1.9 as well (since 1.9.10):
https://ant.apache.org/manual-1.9.x/Tasks/conditions.html

Where do you want to place this test, and what version to check?

Compilation is expected to be done with Java 11, but tests can be run with an earlier version, IIRC.
Comment 2 Michael Osipov 2023-09-28 13:59:01 UTC
(In reply to Konstantin Kolinko from comment #1)
> It is supported in Ant 1.9 as well (since 1.9.10):
> https://ant.apache.org/manual-1.9.x/Tasks/conditions.html
> 
> Where do you want to place this test, and what version to check?

It should be tested right after https://github.com/apache/tomcat/blob/29aaefd2944d6ec50505c21d6fd0346a71360388/build.xml#L41-L54
 
> Compilation is expected to be done with Java 11, but tests can be run with
> an earlier version, IIRC.

This seems to be a good point, toolchains missing here.
Should it go like:
JAVA_VERSION=11 ant compile
JAVA_VERSION=8 ant test
? Does one use this?

One can also pass a JVM argument to <junit /> for another VM, not the one in PATH as far as I can see.

Err, looking at https://github.com/apache/tomcat/blob/15927d179401cbc7f82ef8ae1b7c01148b1177f1/build.xml#L1976-L1980 this is not the case anymore. So Java 11 or bust. This is what I have seen as a failure for me when running Tomcat 9 with Java 8 at test time.
Comment 3 Christopher Schultz 2023-09-29 12:12:24 UTC
(In reply to Michael Osipov from comment #2)
> > Compilation is expected to be done with Java 11, but tests can be run with
> > an earlier version, IIRC.
> 
> This seems to be a good point, toolchains missing here.
> Should it go like:
> JAVA_VERSION=11 ant compile
> JAVA_VERSION=8 ant test
> ? Does one use this?

This is what I do for 8.5: build using Java 11 and run all testing using Java 8.

I set JAVA_HOME and run "ant test".

https://github.com/ChristopherSchultz/apache-tomcat-stuff/blob/master/bin/test-tomcat-release.sh

> So Java 11 or bust.

Java 11 is only required for the build. For testing you can:

https://github.com/ChristopherSchultz/apache-tomcat-stuff/blob/master/bin/test-tomcat-release.sh#L269-L279
Comment 4 Christopher Schultz 2023-09-29 12:14:08 UTC
+1 to adding this version check. Anything that causes the build to fail earlier is a Good Thing if it's gonna fail, anyway.
Comment 5 Michael Osipov 2023-10-12 12:17:34 UTC
(In reply to Christopher Schultz from comment #3)
> (In reply to Michael Osipov from comment #2)
> > > Compilation is expected to be done with Java 11, but tests can be run with
> > > an earlier version, IIRC.
> > 
> > This seems to be a good point, toolchains missing here.
> > Should it go like:
> > JAVA_VERSION=11 ant compile
> > JAVA_VERSION=8 ant test
> > ? Does one use this?
> 
> This is what I do for 8.5: build using Java 11 and run all testing using
> Java 8.
> 
> I set JAVA_HOME and run "ant test".
> 
> https://github.com/ChristopherSchultz/apache-tomcat-stuff/blob/master/bin/
> test-tomcat-release.sh
> 
> > So Java 11 or bust.
> 
> Java 11 is only required for the build. For testing you can:
> 
> https://github.com/ChristopherSchultz/apache-tomcat-stuff/blob/master/bin/
> test-tomcat-release.sh#L269-L279

Wow, hacky. With this possible, how one enforce the build JDK version of 11 if you stil want to use 8 to test?
Comment 6 Michael Osipov 2023-10-12 13:54:35 UTC
Fixed in:
- main for 11.0.0-M13 and onwards
- 10.1.x for 10.1.16 and onwards
- 9.0.x  for 9.0.83 and onwards
- 8.5.x for 8.5.96 and onwards

Chris, I have addded a property for 8.5 and 9.0 to disable this check to be able to run tests with older Java versions.
Comment 7 Michael Osipov 2023-10-12 14:52:51 UTC
Also fixed in:
* tomcat-native main for 2.0.7 and onwards