Gradle refresh sets node_modules as my module content root
Note: I've substituted our actual project name with "myProject".
Every time I run "Refresh all Gradle projects" from the Gradle sidebar, it sets the node_modules folder as a content root for my "myProject_main" module; when importing the project, I checked "Create separate module per source set".
I have to manually open the "Project structure" dialog and remove node_modules as a content root for the module, and when I do this, I get the "Module 'myProject_main' is imported from Gradle. Any changes made in its configuration may be lost after reimporting." warning. If I don't do this, the Kotlin compiler fails to find any sources when I run my build through IntelliJ. I can't think of any reason this would be happening, and it just started happening randomly today.
Since then, I've tried "Clear caches and restart", I've tried using the Gradle Idea plugin, but I couldn't figure out how to configure each module since in the build.gradle it was configuring a top-level "myProject" module, but I have separate modules per source set, so instead of one "myProject" module, I have "myProject_main" and "myProject_test".
If there's a way to configure each source set module from the single build.gradle at the project root without adding any new gradle files, that would be a fine solution; I just couldn't figure out a way to do this, or find anything like it in the documentation of the Gradle Idea plugin.
We are using the default Gradle sourceSets configuration (our build.gradle does not contain any sourceSets { } block). My project structure is as follows:
root/
+-- node_modules/
+-- src/
| +-- main/
| +-- java/
| +-- com.mydomain.myproject/
| +-- test/
| +-- java/
| +-- com.mydomain.myproject/
Please sign in to leave a comment.
Hi. All settings in project structure are being overridden by gradle settings, so you should set your source roots in build.gradle.
By source roots, do you mean using the sourceSets block? Also, it's setting node_modules as my content root, not my source root. Is there a way with the Gradle Idea plugin to configure separate modules per source set without having each source set have it's own Gradle file?
Also, what gradle settings would cause node_modules to be set as the content root? That was sorta the whole question...
Through trial and error I figured out the XML snippet I need to add to .idea/modules/myProject_main.iml, the only problem is that Gradle refresh removes this section because it syncs module config with Gradle. I need to figure out how to get my Gradle config to result in having this XML in .idea/modules/myProject_main.iml:
Try using exclude in build.gradle as described here: https://stackoverflow.com/questions/12617827/gradle-1-2-exclude-directory-under-resources-sourcesets
This does nothing. The same issue still occurs.
Try using ExcludeDirs from ideaModule: https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
the problem is that I can't configure separate modules per source set that way, or at least I can't figure out how to.