在 IntelliJ IDEA 中使用 Gradle 导出时,资源文件夹不包含在 JAR 文件中

Resources folder is not included in the JAR file when exporting it using Gradle in IntelliJ IDEA

资源文件夹 /src/main/resources 被标记为 Resources Root,但在使用项目模块的 Gradle 构建工件时未包含在 JAR 文件中.

我尝试将它包含在 build.gradle 中,但它仍然没有出现。如何修改 项目结构 以包含资源文件夹?

如果我 运行 ./gradlew jar on your project 在评论中提到,那么生成的 build/libs/MyApp-1.0-SNAPSHOT.jar 文件包含来自 [=13= 的 directories.txt 文件】 不出所料。所以 Gradle 设置是正确的。

听起来您的 IntelliJ IDEA 项目配置不正确。您不应手动篡改项目设置,而应让 IntelliJ Gradle 插件负责配置项目。 Here 如何将项目正确导入 IntelliJ:

  1. If no project is currently opened in IntelliJ IDEA, click Open on the welcome screen. Otherwise, select File | Open from the main menu.
    If you have some custom plugins that require you to import your project from the IntelliJ IDEA model, press Ctrl+Shift+A and search for the Project from Existing Sources action.
  2. In the dialog that opens, select a directory containing a Gradle project and click OK.
    IntelliJ IDEA opens and syncs the project in the IDE.

If you need to adjust the Gradle settings options, refer to Gradle settings.