How do I tell IntelliJ to ignore build.gradle files under node_modules?
Answered
I'm a full stack developer and have a IntelliJ project with both Java and React/Javascript in it.
IntelliJ is trying to process a build.gradle file that is under node_modules and failing.
It keeps happening and disrupting my work.
How can I disable this "feature"?
Thanks.
The file is /home/user1/myproj/reactApp1/node_modules/less/build.gradle
NOTE: The node_modules directory is already marked as excluded so I'm not sure what else to do.
I tried disabling the gradle plugin, but that was not an option that I was given when I selected the plugin.
Please sign in to leave a comment.
>IntelliJ is trying to process a build.gradle file that is under node_modules and failing.
What exactly is happening?
You can un-link the Gradle project (if it was indeed linked into your project) from the Gradle tool window, see Unlink a linked Gradle project.
@...,
The Problems tab (View | Problems) lists these build.gradle files as "in error" (they might be but I just need IntelliJ to ignore them). These errors are in a Javascript project under the node_modules directory. That just shouldn't happen (IMO).
If I were to request a fix, it would be to have IntelliJ (by default) ignore all gradle files under the node_modules directory as the the files under node_modules are "imported build files" and are never to be used for development and never be built.
Again the directory that had the gradle file was:
/home/user1/myproj/reactApp1/node_modules/less/build.gradle
-----------------------------------------------------------------------------
Tried work around
Your link Unlink a linked Gradle project. helped me out, as I could remove what IntelliJ thought were gradle projects in my Javascript project.
I should add that, IMO, that project should never distribute the build.gradle file as well, but IntelliJ could also handle this shortcoming.
Work Around (is mostly acceptable):
To be clear, the work around (in my case) was acceptable. I had three NPM projects that used the less npm module and so I simply went to the gradle tab/view and deleted these gradle projects from IntelliJ.
The problem is that the three gradle errors remain in the Problem's view even after the files have been removed as Gradle configurations.
And after removing the project from the Gradle Tool Window, I can't open the Gradle Tool Window anymore because the Gradle choice has been removed.
>The problem is that the three gradle errors remain in the Problem's view even after the files have been removed as Gradle configurations.
Could you clarify, what is the error text which is reported for them?
>And after removing the project from the Gradle Tool Window, I can't open the Gradle Tool Window anymore because the Gradle choice has been removed.
Why is it needed to use Gradle tool window? Thanks.
>If I were to request a fix, it would be to have IntelliJ (by default) ignore all gradle files under the node_modules directory as the the files under node_modules are "imported build files" and are never to be used for development and never be built.
Actually, IDE must never automatically add build.gradle files from sub-directories of the project. It will only use the build.gradle in the root project directory and treat it as a gradle project when you open it for the 1st time. In other cases IDE shows the notification that Gradle build files were detected when you may choose to import them as Gradle modules or ignore them.
Andrey Dernov, I decided to create a simple example to illustrate the problem.
I was able to recreate the problem as follows:
(1) Create a top level directory that will eventually have two sub-directories. npm-proj and spring-boot-proj.
(2) Create the npm proj as follows
(3) At this point I started IntelliJ and opened the directory intellij-error as a project.
(4) Next (inside IntelliJ), I created a spring-boot module that included Web.
(5) I was prompted to import a gradle project so I did.
(6) This resulted in the error I've described above (later there is a picture of it).
(7) From the Gradle Toolbox, I removed "less" from the gradle the list of things that it would treat as gradle.
(8) The error still remained in the Problems View. There is no way to remove this error.
The image below shows the error
Unable to add image sorry, I'll do another post with the image
The image below also shows the error.
Hope this helps understand what I was talking about.
So this remains in the Problems view, there is no way to clear them out.
I tried adding the image below to my previous post during an edit, but a bug in the editor prevented the image from being uploaded properly. Here is the image.
>(3) At this point I started IntelliJ and opened the directory intellij-error as a project.
When I open such a directory with build.gradle file inside node_modules - IDE does not auto import it. It prompts about found build Gradle files which you may choose to import or ignore:
>(4) Next (inside IntelliJ), I created a spring-boot module that included Web.
>(5) I was prompted to import a gradle project so I did.
The Gradle import is always automatically initiazted after creating the Spring Initializr Gradle based project(or module), so IDE should not prompt for any additional import here:
>(8) The error still remained in the Problems View. There is no way to remove this error.
The IDE will validate the file if you have it opened in the Editor, enev if it is in excluded directory. Try to close the file and reopen the project.
If you still see the issue, please check if the directory where the file is located is excluded.