如何设置 Intellij 复制资源目录而不仅仅是目录内容?

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

我想在我的 Intellij 项目中设置一个文件夹作为测试资源文件夹,并让 Intellij IDE 将整个文件夹复制到我的输出目录并保留顶级文件夹。

例如,这是一个基本的项目结构:

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

应该像这样编译并创建一个输出目录:

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

问题是,只需将 test-configurationfiles 目录标记为 Test Resources Root(或Resources Root)文件夹,始终生成以下输出目录结构:

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

Intellij 似乎只复制资源文件夹的内容,而不是整个目录。有没有办法设置Intellij复制根目录来维护输出中的目录结构?

不,没有这样的方法。资源 root 就是:一个目录,其内容被复制到输出目录的 root。如果您需要额外的结构,您需要创建一个 "resources" 目录,将其标记为资源根目录,并将您的 "test-configuration" 和 "files" 目录移动到其中。