【问题标题】:Gradle 1.2: Exclude directory under resources sourceSetsGradle 1.2:资源sourceSets下的排除目录
【发布时间】:2012-09-27 09:08:23
【问题描述】:

我有一个外部库需要的开发相关目录src/main/resources/certs/test。这有一些生产构建中不需要的证书文件。

目前,我在build.gradle 中使用以下块排除该目录下的所有内容:

sourceSets {
    main {
        resources {
            exclude '**/test/*'
        }
    }
}

这很好,但留下丑陋的空目录test 躺在那里。在最终战争中不包含此目录的选项有哪些?

我尝试排除'**/test',但它根本不起作用。

我使用战争插件和 Gradle 1.2

【问题讨论】:

    标签: gradle


    【解决方案1】:

    使用 Gradle 1.1,这对我有用:

    apply plugin: 'war'
    
    sourceSets {
        main {
            resources {
                exclude '**/test/*'
                exclude 'certs/test'
            }
        }
    }
    

    【讨论】:

    • 您可以使用以下命令排除每个文件和文件夹及子文件夹:resources { exclude '*.*' exclude '**/' }
    【解决方案2】:

    JAR 文件中的生产文件也有类似的问题(尽管我的不是测试文件)。我用以下方法解决了它:

    jar {
        exclude ("DIRECTORY-TO-EXCLUDE/**")
    }
    

    例如

    jar {
        exclude ("test/**")
    }
    

    【讨论】:

      【解决方案3】:

      一个常见的项目布局是将测试文件放在test 源集下,这样您就不必将它们从main 源集中排除。

      来自Gradle documentation,默认项目布局是这样的:

      src/main/java       Production Java source
      src/main/resources  Production resources
      src/test/java       Test Java source
      src/test/resources  Test resources
      

      【讨论】:

      • 我知道标准布局。问题不在于我的项目的布局以及它的标准程度,而是 Gradle 排除目录的功能。我可以重新格式化我的项目,但最初的问题仍然存在。
      • 这个布局是标准的,也是totally impractical(搜索“项目布局”)。放下它是我每天都喜欢的事情。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多