vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

.classpath keeps changing to Java 1.8, not what is in pom.xml (11)

Open naris opened this issue 3 years ago • 5 comments

I have a project that was generated by JHipster that has always used Java 11, which is specified in the POM.

        <java.version>11</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>

However, every time .classpath is generated it specifies Java 1.8:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

Then I have manually change it to java 11:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">

This is similar to this issue .classpath file is not updated with new JDK version #1748 where they said to manually trigger a configuration update with the "Update Configuration" command. I have done that and it also changes it to Java 1.8 :/

Environment
  • Operating System: Windows 10 Enterprise 10.0.19044 Build 19044
  • JDK version: 11
  • Visual Studio Code version: 1.68.0
  • Java extension version: v0.23.0 (Last updated 6/12/2022, 20:07:00)
Steps To Reproduce
  1. manually trigger a configuration update with the "Update Configuration"
  2. Java version changes to 1.8, NOT the version in pom.xml

[Please attach a sample project reproducing the error] Please attach logs

Current Result

.classpath is configured for Java 1.8, not the version specified in pom.xml

Expected Result

.classpath should match the pom.xml file, which is configured for Java 11

Additional Informations

naris avatar Jun 15 '22 14:06 naris

please attach a sample project

fbricon avatar Jun 15 '22 14:06 fbricon

I am observing the same behaviour... downgrading from 1.7.0 to 1.6.0 resolves the issue after a clean java workspace.

karlvr avatar Jun 18 '22 01:06 karlvr

@karlvr I can't reproduce the issue. Could you attach a project sample?

snjeza avatar Jun 18 '22 01:06 snjeza

I had a very similar issue with JavaSE-11 being changed to JavaSE-12 automatically by vscode in my maven java projects. In my case it was caused by maven-enforcer-plugin. When I changed the version underneath plugin/executions/execution/configuration/rules/requireJavaVersion in

	<plugin>
		<artifactId>maven-enforcer-plugin</artifactId>
		<version>3.1.0</version>
		<executions>
			<execution>
				<id>enforce-java</id>
				<goals>
					<goal>enforce</goal>
				</goals>
				<phase>validate</phase>
				<configuration>
					<rules>
						<requireJavaVersion>
							<version>11.0.4</version>
						</requireJavaVersion>
					</rules>
				</configuration>
			</execution>
		</executions>
	</plugin>

from <version>11.0.4</version> to <version>[11.0,12.0)</version>, then it stopped changing the java version.

Maybe it is also some maven plugin in your case causing this?

kkalass avatar Jun 22 '22 13:06 kkalass

@kkalass thanks for the tip, this is what my maven-enforcer-plugin was set to:

<requireJavaVersion>
	<version>[1.8.0,)</version>
</requireJavaVersion>

It doesn't feel like I got the right result, as 1.8.0 is just the minimum and it chose 1.8 even though I have both 11 and 17, but changing that to 17 has fixed the issue with VS Code choosing 1.8 for my project in spite of the compiler plugin stipulating 17. Much thanks.

karlvr avatar Jul 05 '22 07:07 karlvr

This may have been related to https://github.com/eclipse-m2e/m2e-core/issues/1099 so if it's still an issue, feel free to re-open. Explanation seems to be that under Eclipse, the JRE used to run the project is the same one used to run Maven.

rgrunber avatar Jan 22 '24 22:01 rgrunber