gradle build: intellij hot swapping not working anymore?

LabKey Support Forum
gradle build: intellij hot swapping not working anymore? Ben Bimber  2017-11-20 17:28
Status: Closed
 
I'm on 17.2, intellij 2017.2.5. I think I set up my dev machine following the LK instructions. My dev instance runs fine; however, when i try to hot swap java code (ctl + shift + F9), I get errors like 'Cannot find symbol AbstractTableInfo'. These errors typically involve not finding something in API. Should I be able to hot swap using the gradle config, and is there something else I need to configure to allow it? Thanks.
 
 
Jon (LabKey DevOps) responded:  2017-11-21 11:50
Hi Ben,

My understanding is that you should be able to. Did you try to do the hot swap after doing what would be a rebuild?

So with gradle, you'd do a:

gradlew cleanbuild deployApp

Various StackOverflow posts with similar issues all seem to indicate a need to compile the whole project or the dependent class.

Regards,

Jon
 
Jon (LabKey DevOps) responded:  2017-11-21 12:09
Hi Ben,

Josh also reminded me that a Gradle sync needs to be done in IntellJ too.

Per the docs (https://www.labkey.org/Documentation/wiki-page.view?name=devMachine), under the "Configure the LabKey Project in IntelliJ" section:

Open the Gradle tool window at View > Tool Windows > Gradle.

Click the refresh icon. This will take as much as 15-30 minutes. You should start seeing messages about its progress. If not, something is probably hung up. Wait for this sync to complete before progressing with further IntelliJ configuration steps.

Regards,

Jon
 
Ben Bimber responded:  2017-11-22 10:20
Hi Jon,

Thanks, unfortunately no change yet. The errors I'm currently seeing are primarily about not being able to find org.json.JSONObject, so I wonder if something is not explicitly declaring that dependency or something...
 
jeckels responded:  2017-11-22 11:44
Hi Ben,

org.json.JSONObject is just checked in as source code in the API module. I assume you have it available in server\api\src\org\json\JSONObject.java.

Does IntelliJ seem happy with that file? Are you seeing errors in the source editor for files that reference it, or just when you try to do the IntelliJ build to initiate the hotswap?

Thanks,
Josh
 
Ben Bimber responded:  2017-11-22 11:54
Hi Josh,

Gradlew deployApp works fine; within intellij build (Build menu -> rebuild project) also works fine. I only hit this problem when i try to hot swap a file (ctl + shift + f9). these errors only appear in the intellij message window, not in the source code. this leads me to believe something is out of whack in the intellij config, not apparently not all of it.
 
jeckels responded:  2017-11-27 14:43
Hi Ben,

When doing a build of an individual file, IntelliJ is very unlikely to compile any dependencies outside of that single .java file. Have you completed a full project build within IntelliJ first? If that completes successfully, IntelliJ should reuse those results to allow for the incremental, single-file builds via Ctrl-Shift-F9.

Thanks,
Josh
 
Susan Hert responded:  2017-11-27 19:09
Hi, Ben,

It is also worth mentioning here that the latest versions of IntelliJ will put the output files generated by the gradle build done within IntelliJ in a directory called "out" at the root of the modules' source (e.g., server/modules/core/out). This resulted in a couple of bugs in our gradle plugins, which have been fixed in the version 1.2 of the gradlePlugins jar (compatible with LabKey 17.2 and later). This version also introduces a task 'cleanOut' for each module, which will remove the out directory that IntelliJ creates. See the description in the tasks list (e.g., ./gradlew :server:modules:core:tasks) for the full path of the directory that will be removed by this task. To remove all of the 'out' directories, simply run the cleanOut task at the root level (i.e., ./gradlew cleanOut).

Susan
 
Ben Bimber responded:  2017-11-27 19:58
Hi Susan,

Thanks - I happen to be running a branch based on 17.2 and am using gradle plugin version 1.1. Are you suggesting switching this to use plugin version 1.2 potentially help this problem? you said earlier versions had bugs - does this sound like a known bug?

Thanks,
Ben
 
Susan Hert responded:  2017-11-27 20:35
Hi, Ben,

Josh's suggestions regarding doing a full project build within IntelliJ is probably the real answer to your problem. I mention the 1.2 version of gradlePlugins only because that 'cleanOut' task can be handy if you encounter problems where the IntelliJ build output is getting in the way or somehow not updating when you think it should. The actual bugs we had because of the "out" directories should have been fixed with version 1.1.

Susan
 
Ben Bimber responded:  2017-11-29 10:47
Alright. I made a clean enlistment, and am now getting errors when doing a rebuld via intellij (though the gradle builds run fine). This might actually be progress. A number of classes in API that are saying they are unable to find com.google.commons classes. For example, in org.labkey.api.data.Parameter, the imports turns red and says "com.google.common.primitives.Ints" doesnt exist. If I control-click on 'primitives' I see I have both guava 17.0 and 19.0, and I can find 'Ints'. Have you seen anything like this before?
 
Jon (LabKey DevOps) responded:  2017-12-11 13:22
Hi Ben,

Can you supply the full error that appears? Is it something like a class error, like "java.lang.NoClassDefFoundError" or something similar?

Thanks,

Jon
 
Ben Bimber responded:  2017-12-11 14:02
Hi Jon,

Attached is an export from intellij's console after rebuild (Build -> Rebuild Project). Parameter.java is a good example. Errors are along the lines of:

C:\discvr17.2\server\api\src\org\labkey\api\data\Parameter.java
    Error:Error:line (19)java: package com.google.common.primitives does not exist
    Error:Error:line (451)java: cannot find symbol
  symbol: variable Ints
  location: class org.labkey.api.data.Parameter
C:\discvr17.2\server\api\src\org\labkey\api\view\template\ClientDependency.java
    Error:Error:line (18)java: package com.google.common.collect does not exist
    Error:Error:line (127)java: cannot find symbol
  symbol: variable Sets
  location: class org.labkey.api.view.template.ClientDependency

Which doesnt make sense to me since google commons should be available. I have Intellij 2017.2.5 and am running a branch based on 17.2. I am using gradle plugin 1.2. 'gradle deployApp' works fine, so I assume this is something Intellij isnt getting right.

Thanks,
Ben
 
Jon (LabKey DevOps) responded:  2017-12-13 21:23
Hi Ben,

There's got to be some kind of disconnect between what the IntelliJ build is using compared to the rest of the configuration.

Can you send us a few screenshots of the Dependencies tab for the specific module under File > Project Structure? There might not be any kind of smoking gun there, but it's worth taking a look.

Also, have you tried to have IntelliJ regenerate your .iml files by removing the <LABKEY_ROOT>/.idea/modules directory, followed up with a gradle refresh?

One of the ideas is that your .iml files may be out-of-date or possibly corrupt for some unknown reason, so a regeneration might help to resolve this.

Regards,

Jon
 
Ben Bimber responded:  2018-01-03 09:15
Hi Jon,

I switched to a 17.3-based branch and hot-swapping seems to be working OK now. It's possible my 17.2 issue was something to do w/ the set of modules I have enabled (which probably differs from most LK devs). agreed there was probably something out of sync w/ intellij, but it's not really worth debugging further.

Thanks,
Ben