Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend java source version configuration (maven)
Xtend java source version configuration (maven) [message #1868121] Thu, 11 July 2024 15:26 Go to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 471
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Dear all,

I have Eclipse xtend plugins that have a lower Java compatibility level than the JRE/JDK used for compilation. In particular, I'd like to use OpenJDK21 for compilation, but the plugins are still at Java17.
The maven plugin configures the property javaSourceVersion to be lower which implies for instance that xtend extension need to be used for methods such as list.getLast().

However, if the xtend to Java generation is done with OpenJDK21, the javaSourceVersion configuration seems to be ignored, as for instance the method getLast is used in the generated Java code. Interestingly, setting JAVA_HOME to an older JRE implies that the maven org.eclipse.xtend modules produces the "right" code. But this is not a good solution for compilation on a CI server on which paths may change.

What is the method to configure the source code compatibility?

PS: Is it a bug that the javaSourceVersion attribute in class AbstractXtendCompilerMojo is defined by a property with a different name, see below?

@Parameter(property="maven.compiler.source", defaultValue="11")
private String javaSourceVersion;
Re: Xtend java source version configuration (maven) [message #1868124 is a reply to message #1868121] Thu, 11 July 2024 15:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
this is not a generator problem but a linking problem.
and this happens against runtime jdk.
thus we have introduced new methods to avoid this situation
https://eclipse.dev/Xtext/releasenotes.html#/releasenotes/2024/05/28/version-2-35-0


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Thu, 11 July 2024 15:40]

Report message to a moderator

Re: Xtend java source version configuration (maven) [message #1868130 is a reply to message #1868124] Thu, 11 July 2024 17:37 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 471
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Thanks for the swift answer, but my problem is a different one (sorry, if that was not clear):
I want to generate Java code that is compatible with Java-17, not with Java-21. But the generation is done with an OpenJDK-21. And it currently seems that the JDK used for generation determines the code compatibility of the generated Java code and not the configuration.
Re: Xtend java source version configuration (maven) [message #1868136 is a reply to message #1868130] Thu, 11 July 2024 18:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
The Xtend code generation has no differences in any Java versions >= 8
The problem is a linking problem
Not a generation problem

If you link against 21 it will emit calls into 21.
So you need to avoid this

This is what the new LastOrNull as replacement for last will do


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtend java source version configuration (maven) [message #1868139 is a reply to message #1868136] Thu, 11 July 2024 18:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
See also https://github.com/eclipse/xtext/issues/2981

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtend java source version configuration (maven) [message #1868157 is a reply to message #1868139] Fri, 12 July 2024 09:26 Go to previous message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 471
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Thanks, I could resolve the compilation problems by replacing all .last calls by .lastOrNull calls.
Previous Topic:Xtext 2.36.0.M1 is out
Next Topic:Formatting conflict
Goto Forum:
  


Current Time: Thu Dec 05 07:15:57 GMT 2024

Powered by FUDForum. Page generated in 0.03519 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top