-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
configure mill to use specific java version #2250
Comments
one option might be .env/jenv support? |
Currently, you can't select a different Java version than Mill itself runs with. Zinc has support for it, by setting a As a workaround, you could start Mill with different JDKs. Mill supports the Just set the
|
The tricky part here is to make intellij respect that setup. When i compile in intellij bsp project (from the build menu), it sometimes (depending on java setup order, but then consistently) used java 17 even though I set everything (global sdk, project sdk, module java versions, references in project xml, jenv, sdkman) to use java 11. Is there a way to force bsp to use a certain environment? Is bsp using zinc and jdkHome would work? how can i tell intellij to pretty please use a certain environment? |
Unfortunately I can't answer all these IntelliJ questions. Mill and Mill's BSP server is using zinc, but although zinc can run with a custom JDK home, we currently have it not implemented. An implementation would probably add some new |
The intellij integration is crucial for adoption. Many companies have to use different java versions and being able to configure easily is important. |
Contributions are welcome. |
If someone were to want to work on this, (no promises at this time! I'm especially frustrated that zinc apparently has no documentation, not even scaladoc, so where does one even start?) what should it look like? Should it be just a way to pass an explicit path to zinc? Or should it be a little more sophisticated, something like gradle's "toolchain"? Toolchain-like would provide the following:
|
I think a good start would be to analyze the same feature from sbt. I think, they require each user to have a local configuration file, which maps locally installed JDKs to names. These names can be referenced from the build file. Following this trace and settings keys in the sources might hopefully lead to the relevant zinc API. This is just from vague memory. I never used sbt to that extends and only skimmed the other day through some code/examples, but maybe it helps. |
Just took a peek at sbt repo, I don't think sbt use zinc API to run with custom JDK. What it does is:
I wonder if we can adapt this by adding |
Same here. My work around is adding the following line at the begining of the mill script (after the JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home FurthermoreI replaced the line with the following lines so that different developers may set different path of JDK of their own via if [ -f ".mill-java-home" ] ; then
JAVA_HOME="$(head -n 1 .mill-java-home 2> /dev/null)"
fi |
@lefou |
@llvee I think everything proposed above are either workarounds or just ideas. Ideally, we can declare an optional JVM/JDK version in a Java module, and Mill is either automatically fetching and using it if not present, or has some other means of accessing this JVM/JDK version (local config file, env variable, ...). E.g. older JDKs from Oracle can't be downloaded automatically in a legal way. Some users might also want to use patched JDKs (thinking of VMs with hot class replacement setups). |
Ok, is the ideal solution expected to also focus on IntelliJ compatibility? From my understanding, the desired outcome is that Mill can be used with any project, understand/use the correct JDK based on individual projects using JAVA_HOME env. Is that correct? |
The system environment variable The retrieval logic could be just downloading and caching it. Since older JDKs often imposed download restrictions, other build tools sometimes invented some config file and required the user to download and configure JDKs for later use. Whatever we end with, it should come with reasonable documentation. Ideally, we also support these new configurations in |
We should therefore aim for a solution that can be applied to all kind of SDKs. One proposal is to look up a local config that matches the configured |
Should be mostly resolved by #3716 which would go out next releaes 0.12.3 |
how can I tell mill to use a specific java version to compile/run the code/itself?
I have many different projects with many java versions.
The text was updated successfully, but these errors were encountered: