-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Set the jvm arguments of the gradle compiler deamon #1461
Comments
@ghale IIRC there was recent work in this area, correct? Do you have any information for @blackdrag here? |
You should be able to do this by setting the fork options on the compile task. For instance:
This is documented through the DSL reference (https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html) although it would probably require some digging. |
Right, thanks Gary. For some reason I had it in my head that that didn't affect the compiler daemons. Closing as answered. Please reopen @blackdrag if anything is amiss. |
I don´t think I have the access rights to reopen the issue. Because I already had this before I filed this issue:
What I had expected to happen was the build script compiler daemon to fail to start because of the invalid JVM option. That did not happen, nor did the option show up in the log:
If this is supposed to work for Gradle 3.2.1, then it has a bug. I just checked against 3.4 and there we have:
Which does not look all that different to me and still fails to include my JVM option. It does not even include GRADLE_OPTS. I know the option works for forked javac´s, but the build source is different. And if this is supposed to be the right way, to do it, then consider this a bug report, because it does not work, and blocks me from using JAVA9 with jigsaw |
one more thing. On github I can reopen an issue only if I closed it. Since @eriwen closed this issue I cannot reopen it |
@blackdrag I assume this is for
I'm guessing something else is going on here (possibly something overwriting jvmArgs later in build script?). Is your not-working configuration on a branch or somewhere that I could take a look at it? |
OK, actually I just took a closer look at your code snippet above and I think I know what the problem may be. You have the following commented out:
|
This is for groovy-core, yes, and I will try soon. But could you explain "in process" a bit more? Because it is not the process I start with the gradle command, that I can influence using GRADLE_OPTS. Why is gradle creating separate process for the builder daemon, but lets you set options for it only in fork mode? |
ok, after trying out for a few minutes... Is it possible this behaves different on jdk8 and jdk9? Because my "---fooo" seems not to appear using:
|
an I did just see I still have artefacts from several tries before... So I also have
in gradle.settings and also org.gradle.daemon=false. But as you can see setting the daemon to false does not prevent the creation of the builder daemon. Which leads me back to not understanding the handling of this build script daemon. I mean why is a fork option on compileJava controlling (yet to be verified) the buildscript daemon? Why can`t I disabled the usage of daemons with org.gradle.daemon=false anymore? why does the build script daemon ignore org.gradle.jvmargs? Why does the daemon not take GRADLE_OPTS? You see I am hopelessly lost and I am probably circling around a bit because I have no clue about how things are working anymore and it would help understanding how things are supposed to be working at least. At this point I can´t even tell if the forked JVMs for compileGroovy or compileJava have anything to do with the one for the build script. My assumption would have been that I can set these separately, but your suggestion is telling me other things. I would have thought for example that we could have the build script compilation even without a java or groovy compiling build. How does it then make sense to use compileJava fork options to control this? Really, not ranting here, just trying to understand the workings of this build script daemon. |
I got the same issues here with the latest There is a epic #890 that should add support for JDK 9 also, unfortunately there where no actual updates since January. I would like to help out in testing more in this area, but did not jet receive any response jet. At last, I saw that you still use the |
@reinhapa I actually used only
|
So, a couple of different things going on here and hopefully I can clear some things up. There are two different "daemons" in play here. There is the "Gradle" daemon and then there are compiler daemons. The Gradle daemon is a long-running process that stays alive after the build is done and maintains all sorts of state about your build so that the next time a build is run, it's warm and everything runs faster. You can think of them as a build process that runs a build but instead of exiting, waits for additional build requests. When you set With respect to the compiler daemons, you can either run them in-process or out-of-process. "In-process" means they run in the build JVM (i.e. the Gradle daemon) and compilation is done using the Now, aside from JVM arguments for the compiler daemon itself, there are also compilation arguments which are the arguments to use for a particular compilation task (and which are passed to the underlying I hope this clears some things up. Let me know if anything is not clear. |
I've been working with JDK9 since the early builds. The restriction on setAccessible was a big step backward for Gradle. While it's possible to add --add-opens to the environment generally, it does open it up for other software beside Gradle. On the other hand, trying to change every project build.gradle to have the right packages opened is very invasive. The solution that I found worked best in our environment was to introduce a shell script to invoke Gradle. In the shell script, when running with JDK9 I export _JAVA_OPTIONS with all of the --add-opens arguments needed for all of the projects in our build. It's also a good place to add -Dsun.reflect.debugModuleAccessChecks=true to track down additional packages that need to be added. I was trying to figure out if there is anything else that is needed (the environment is pretty complex). Meanwhile, we would really like to see Gradle and Groovy fixed. I know that this approach to open packages is likely hiding a few more changes that are needed in the product code. |
@sdfelts Goal of this is to be able to run a build with JDK9. Fixing general JDK9 problems of Groovy is not the goal here. For those it is probably better to run gradle with a JDK8 and run all the forked compilations and tests with a different JDK:
and for compilation you already provided a way to use a different JDK. The Groovy problems with JDK9 I have seen so far (just normal classpath based projects without additional modules) seem not to have a problem with recent Groovy. I am very sure that is only because of the reluctant testing though. But for Groovy errors in Gradle...most of those are because here Groovy was used to bypass restrictions. There is no fix for these on the Groovy side short of rewriting java module descriptors on startup. And that is because of the way the module system is designed and its additional restrictions it imposes on everyone. And actually non of these problems are actually specific to Groovy. For most of these solutions you would probably have used reflection and it would have failed by now as well. |
@blackdrag Any new findings or even solutions regarding the "compiler daemon" issue? I'm stuck at a similar build-show-stopper here: https://travis-ci.org/junit-team/junit5/builds/219179434#L1029 Using "--no-daemon" on the initial "gradlew" call and:
|
@sormuras try using a very recent jigsaw build and then
plus in the gradle.properties:
I had not yet the time to actually try this out though. If you did try this, it would be very nice if you could report if it was of any help |
And leave the daemon "alive and kicking" enabled? |
as I mentioned in my post above on March 7, I use _JAVA_OPTIONS to get JDK9 command line arguments from the command line to all embedded processes. We call gradle from the command line, ant, shell, etc. There are no problems running gradle or the related daemons (no need to turn them off using --no-daemon). When b163 arrived, I put in a switch so that I can either run with the single --permit-illegal-access or the twenty five or so--add-opens. The --permit-illegal-access has the disadvantage that it prints out warnings even for places in the code that have fall-back code when the setAccessible fails. I've been building up a list of known cases that I can ignore. It's a great way to run the first time to get all of the problem packages in one pass instead of fixing one and re-running to the next one (annoying if you have hundreds of modules). |
This is my gradle shell. It adds JDK9 options for running gradle to the other options needed for my project code. That allows me to isolate as much as possible the gradle/groovy dependencies. if [ " |
@sdfelts Thanks for the comments and hints. If I read your shell script and understand its usage correctly, it is used to initially start gradle with the vm options needed/wanted. But what about the compile daemons @ghale talks about? What about vms that are spawend internally by Gradle? Subprojects, See, we have a "green" build with "--no-daemon": https://travis-ci.org/junit-team/junit5/builds/219396869 |
@sormuras setting the fork options for groovy compile does not work? |
seems using |
I have been using _JAVA_OPTIONS to get gradle working for over a year. |
It did not work. But after your " seems using _JAVA_OPTIONS works " I didn't investigate any further that path.
Thanks @sdfelts ! I totally forgot about that JDK built-in (undocumented?) feature -- even after you mentioned it here many times. Needed time to digest it. Now, the JUnit 5 build on Java 9 is "green" again: https://travis-ci.org/junit-team/junit5/builds/219592861 |
While _JAVA_OPTIONS is unsupported, there is now a supported equivalent. |
Found the "external" link to the Thanks, again! |
Is this still an issue with Gradle 4.1 and recent JDK 9 builds? Please try by removing all workarounds that you may have added previously. |
The final JDK 9 build (b181) defaults to having all packages opened. All of these workarounds are no longer needed. However, a warning is still printed during the gradle code execution and it should be fixed. |
Thank you for verifying, let's continue on that other issue then. |
while the jdk9 specific problem here got solved by jdk9 diverging from the originally planed logic - I still cannot set the jvm arguments of the gradle compiler daemon. I have not tested with Gradle 4.1 though. |
The compiler daemons are configured via the options on the compile task. If that doesn't work, can you attach a small example that shows the problem? |
How to get memory dump with gradle daemon and javac? The next snippet doesn't work.
|
In the case you want to go to the add-open JVM option, here's a command to find which module provide which package ->
the name of the module will be shown with the @ while the name of the packages without it (tested with JDK 11) |
I am trying to get the Groovy project compiling using Gradle 3.2.1 under jigsaw 155. This time I got blocked by the Gradle Compiler Daemon trying to handle the build scripts. I know how to fix the problem (by adding exports as jvm argument), but I have not found a way to set the jvm arguments of the Gradle Compiler Daemon worker. Here is at least documentation missing. A possible workaround would be to force the build source compilation be part of the same JVM as gradle itself or anything that let´s me set options via GRADLE_OPTS. But I did not find any information on if that is possible either.
The text was updated successfully, but these errors were encountered: