Automatic incorrect marking directory as Resource Root
I have multi module Maven project. One of them is frontend application (Maven uses frontend-maven-plugin to run NodeJS and build Angular app in target).
After build application I have directory "target". I mark "target" directory as excluded ("Mark directory as" -> "Excluded"). Because without this when I search, IntelliJ try to search in files in "target" (it very slow down when you search in bundled files).
But after some time (I don't know exactly what action cause this) directory "target/frontend" is automatically marked as "Resources Root". This is wrong.
I have to unmark this directory manually every time (click on "target/frontend" -> "Mark directory as" -> "Unmark as Resources Root"). Without this I can't use search (because it slows down by searching in bundle files).
How can I disable automatic marking directories? Or how can I mark/unmark directory permanently (when I build application, directory "target" is deleted and created again so I lost my settings)? What files (specific extensions?) can cause that IntelliJ mark this folder as "Resources Root"?
"target/frontend" automatically incorrectly marked as "Resource Root":
Content of "target/frontend" :
请先登录再写评论。
> After build application I have directory "target". I mark "target" directory as excluded ("Mark directory as" -> "Excluded"). Because without this when I search, IntelliJ try to search in files in "target" (it very slow down when you search in bundled files).
The target folder can be excluded by default in
(Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing -> Exclude build directory (%PROJECT_ROOT%/target)
settings. Check that you have enabled the necessary checkbox.> But after some time (I don't know exactly what action cause this) directory "target/frontend" is automatically marked as "Resources Root". This is wrong.
Probably you have configured the
frontend
folder as resources root in yourpom.xml
file. Check your resources settings under the build section. See the official Maven guide to learn how to change it https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.htmlIf everything is fine with
pom.xml
please share a small sample project in which the problem is reproducible and a screenshot from(Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing)
settings.The files can be attached via HTTPS or any other uploading services. (do not forget to clarify the file names)
I have enabled checkbox "Exclude build directory (%PROJECT_ROOT%/target)". But I can't see the difference if enabled or not (I don't know why... maybe because my frontend project is child module of my root module and this option works only for target directory in root module?).
Yes, you're right! I have in my frontend/pom.xml:
I use this for copying resources to frontend.jar.
I noticed that clicking on "Reload All Maven Projects" (on "Maven" tab) causes that IntelliJ automatically marking this directory.
Thank you! Now I know what causes problem and how to trigger marking for testing purposes. I have to find another way to copying frontend resources to frontend.jar (without "<resource>" tag).
My settings (probably default):
> I use this for copying resources to frontend.jar.
I think you can mark the frontend directory as resources root of the module. In this case, Maven will automatically copy the resources from this folder to the target one. For example https://prnt.sc/svqdnc
Thank you, but it doesn't work for me (or I don't know how to use it). I tried (based on your example):
But it doesn't copy files from target to jar. I think we have different project structure. I have to specify path to include resources inside jar. But when I do it, IntelliJ automatically marks it as `Resource Root`.
I found example of project in which you can simply reproduce issue: https://github.com/FraktonDevelopers/spring-boot-angular-maven-build - `frontend` project. (you can rename all `dist/frakton` to `target/frontend` to be sure if it the same case, but I don't see the difference).
By the way, I noticed that the issue doesn't relate only the multimodule project, but also a single module one.
I suspect that option `Exclude build directory (%PROJECT_ROOT%/target)` doesn't work as expected. I reported issue: https://youtrack.jetbrains.com/issue/IDEA-244905
Looks like it's expected behavior in your case. Please see the comment that Andrey wrote in YouTrack.
The problem can be addressed by using resource plugin instead of modifying resources section in pom.xml :
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target/classes/</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../directory-outside-the-module/and-so-on</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>