简体   繁体   English

创建gradle插件时,将生成的Java或Kotlin源放在哪里?

[英]Where to put generated java or kotlin source when creating a gradle plugin?

I'm not quite sure about this - there's usually a directory under /build/generated , but I'm wondering if there is a standard location that's safe to write source files to which also will be included in the compilation? 我对此不太确定-通常在/build/generated下有一个目录,但是我想知道是否有一个可以安全地写入源文件的标准位置,该位置也将包含在编译中? Environment variables? 环境变量? I couldn't find anything in the docs. 我在文档中找不到任何内容。

If it matters, this use case is a single kotlin file which I generate as a separate task based off of configs and want to include in java/kotlin compilation. 如果重要的话,这个用例就是一个单独的kotlin文件,我根据配置将其作为单独的任务生成,并希望包含在java / kotlin编译中。

buildSrc it's a place for custom plugins, and it's a special Gradle folder as well that is read before the build. buildSrc是自定义插件的地方,也是一个特殊的Gradle文件夹,在构建之前已被读取。

As for generated sources, you can just define a source set for it. 至于生成的源,您只需为其定义一个源集。

sourceSets {
  main {
    java {
      srcDirs = [
        "$projectDir/src/main/java",
        "$projectDir/src/main/generated",
      ]
      include '**/*.java'
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM