-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Introduce java version management #181
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.neoforged.gradle.common.extensions; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaPluginExtension; | ||
import org.gradle.jvm.toolchain.JavaLanguageVersion; | ||
import org.gradle.jvm.toolchain.internal.JavaToolchain; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class JavaVersionManager { | ||
|
||
private final Project project; | ||
private int javaVersion = -1; | ||
|
||
@Inject | ||
public JavaVersionManager(Project project) { | ||
this.project = project; | ||
} | ||
|
||
public void setJavaVersion(int javaVersion, String context) { | ||
if (this.javaVersion > javaVersion) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic needs to be the other way around. In the case where there's 2 neo deps in the same project, the project must compile with the lowest Java version so that both sourcesets will work. Compiling with the highest will cause the one needing the lower to crash at runtime, and even if target compatibility were set, one can easily run into the issue of using newer Java methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that the toolchain is used for running too, and for running you definitely need the newest. And NG doesn't currently have an easy way to use a separate javalauncher for a given run configuration it seems? Maybe the real solution would be to add that -- then the runs with a given MC version could use the one for that MC version and the root toolchain would use the oldest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarfy, not just running, also decompile and recompile need the newest versions, so this is the correct default behaviour. |
||
project.getLogger().warn("Can not reconfigure java version from {} to {} for {}", this.javaVersion, javaVersion, context); | ||
return; | ||
} | ||
|
||
this.javaVersion = javaVersion; | ||
project.getExtensions().getByType(JavaPluginExtension.class).getToolchain().getLanguageVersion().set(JavaLanguageVersion.of(javaVersion)); | ||
marchermans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just.. set the version? What's the point of this extension?