Resources in Maven based projects
How does the IDEA build handle resources in Maven based projects?
Is it correct that it only copies those resources on project rebuild that are listed in <resources> or <testResources> tags in the pom.xml?
Is there any way to see in the UI which files will be copied on build?
Please sign in to leave a comment.
I'm not quite sure what you are asking. Anything that is in the resources folders is copied as if they are non-source resources. AFAIK, IDEA uses the pom.xml to build it's project information, then it uses it's project information to perform a build like normal. If you use the Maven integration, then it will use Maven to build the project. Basically anything in those folders will be copied over on build.
To add to what Norris said...
The one caveat is that when the build is run through IDEA (rather than via maven in IDEA or maven command line) any files that match a pattern in the "Ignore files and folders" option at the bottom of the File Types settings dialog (File > Settings > [IDE Settings] > File Types) will not be copied over. for example, if *.foo is listed and you have bar.foo in your resources directory, it will not be copied over when you run an IDEA make or build. Only when you run a maven build (either within IDEA or from the command line.)
Yes, unless you are using the the defaults (i.e. not explicitly declaring <resources> and/or <testResources>).Without an explicit declaration it uses the standard src/main/resource as defined in the super parent pom (or whatever its proper name is ;)) IDEA will honor any <exclude> entries.
File > Project Structure > [Project Settings] > [Modules] > {select a module} > "Sources" tab
Any resource directories will be shown there.
That's not actually correct. If you run any of the actions under the Build menu in IDEA (such as "Make Project" or "Rebuild Project") IntelliJ IDEA runs the build based on the IntelliJ IDEA project's settings. Those settings are imported from the maven configuration and therefore will match resulting in almost identical builds. But again, IDEA itself is running the build. You can see this in the output displayed "Messages" tool window when you launch one of those actions.Where this can become an issue is once you move beyond basic builds in maven. If you use a maven plug-in to do any fancy work (such as generation of additional source code) and IDEA does not have a comparable setting/ability, then that action will not occur.
Obviously if you run a maven goal from the "Maven" tool window, then it is using maven (as shown in the output in the "Run" tool" window).
Thanks for the info. It's good to know that IDEA uses the same patterns that are specified in the pom.xml (currently resources are not located in src/main/resources but right next to the .java files in src/main/java).
I would have missed that ignored files and folders will not be copied. On second thought, that seems logical, though.