问题
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