How to refer to generated source files?

℡╲_俬逩灬. 提交于 2019-12-12 18:58:46

问题


How do I refer to files generated by a sourceGenerators sbt task? I know that the source file is deposited to target/scala-<version>/src_managed/path/to/File.Scala but I don't know how to reference it in my project. Any ideas?

/server
  /app
    /models
      Driver.scala (can't use MyGeneratedCode here)
  /project
    /src/main/scala/
      ModelGenerator.scala  (the code used to create MyGeneratedCode.scala)
    /target/scala-2.12
      /classes
      /src_managed
        /main/generated/
          MyGeneratedCode.scala

回答1:


The generate file works as any normal Scala file but on a fancy folder so it is not tracked by git (or any other VCS).
As any Scala file, it should had a package whatever statement at the beginning, from which you can latter import your classes (import whatever._). Usually the package name matches the directory structure, but they do not have to (specially since it is just generated file).

If it does not have a package, all its members probably resides on the __root__ package. But that probably would cause troubles, I would suggest editing your generator to add a package statement instead.



来源:https://stackoverflow.com/questions/55910013/how-to-refer-to-generated-source-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!