Search code examples
javaintellij-ideaintellij-14

How can I set Intellij to copy resource directories and not just the directory content?


I'd like to set a folder in my Intellij project as a test resource folder and have the Intellij IDE copy the whole folder to my output directory and keep the top level folder in place.

For example, here's a basic project structure:

src/
 - stack/
  - overflow/
   - question/
    - SomeClass.java
tst/
 - stack/
  - overflow/
   - question/
    - SomeClassTest.java
files/
 - testfile.txt
 - testdoc.doc
 - testpdf.pdf
test-configuration/
 - default.properties
 - test-configuration.xml

Should compile and create an output directory like:

out/
 - stack/
  - overflow/
   - question/
    - SomeClass.class
 - test-configuration/
  - default.properties
  - test-configuration.xml
 - files/
  - testfile.txt
  - testdoc.doc
  - testpdf.pdf

The problem is, just marking the test-configuration or files directories as Test Resources Root (or Resources Root) folders, always produces the following output directory structure:

out/
 - stack/
  - overflow/
   - question/
    - SomeClass.class
 - default.properties
 - test-configuration.xml
 - testfile.txt
 - testdoc.doc
 - testpdf.pdf

Intellij seems to only copy the contents of the resource folders and not the whole directory. Is there a way to set Intellij to copy the root directory to maintain the directory structure in the output?


Solution

  • No, there is no such way. A resource root is just that: a directory the contents of which is copied to the root of the output directory. If you need to have additional structure, you need to create a "resources" directory, mark it as a resource root, and move your "test-configuration" and "files" directories into it.