SBT-AVRO没有生成Scala类,可能的设置问题
我正在尝试使用 sbt-avro 在Scala项目中以生成Avro的Scala类模式。
这是项目结构:
multi-tenant/
build.sbt
project/
plugins.sbt
src/
main/
resources/
avro/
Measurement.avsc
scala/
com.mycom.multitenant/
Producer
这是build.sbt(请注意,我尝试使用avrosource设置将SBT-Avro插件指向我的Avro源文件的位置):
version := "1.0"
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.mycom",
scalaVersion := "2.12.15"
)),
name := "multi-tenant",
avroSource := new File("src/main/resources/avro"),
)
libraryDependencies += "org.apache.avro" % "avro" % "1.11.0"
plugins.sbt:
addSbtPlugin("com.github.sbt" % "sbt-avro" % "3.4.0")
// Java sources compiled with one version of Avro might be incompatible with a
// different version of the Avro library. Therefore we specify the compiler
// version here explicitly.
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.0"
在Intellij中构建时 - 正确的绿色锤按钮),没有生成来源。我还尝试在SBT控制台中编写编译
,结果相同。
这是我在Intellij中首次启动SBT控制台时出现的一些日志。它可能包含一些线索:
[info] welcome to sbt 1.5.8 (Oracle Corporation Java 11.0.11)
[info] loading global plugins from /home/sahand/.sbt/1.0/plugins
[info] loading settings for project multi-tenant-build from plugins.sbt,idea.sbt ...
[info] loading project definition from /home/sahand/multi-tenant/project
[warn] Unrecognized repository Scala Plugin Bundled Repository, ignoring it
[info] loading settings for project root from build.sbt ...
[info] set current project to multi-tenant (in build file:/home/sahand/multi-tenant/)
[warn] there's a key that's not used by any other settings/tasks:
[warn]
[warn] * root / avroSource
[warn] +- /home/sahand/multi-tenant/build.sbt:10
[warn]
[warn] note: a setting might still be used by a command; to exclude a key from this `lintUnused` check
[warn] either append it to `Global / excludeLintKeys` or call .withRank(KeyRanks.Invisible) on the key
[info] Defining Global / ideaPort
[info] The new value will be used by Compile / compile, Test / compile
[info] Reapplying settings...
[info] set current project to multi-tenant (in build file:/home/sahand/multi-tenant/)
请注意有关未使用avrosource
设置的警告。也许这就是为什么它不能为我生成来源?它可能根本找不到AVRO源文件。如何解决问题并获得生成的Scala类?
I'm trying to use sbt-avro in a Scala project to generate Scala classes from an Avro schema.
Here is the project structure:
multi-tenant/
build.sbt
project/
plugins.sbt
src/
main/
resources/
avro/
Measurement.avsc
scala/
com.mycom.multitenant/
Producer
And here is the build.sbt (note that I try to point the sbt-avro plugin to the location of my Avro source files using the avroSource setting):
version := "1.0"
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.mycom",
scalaVersion := "2.12.15"
)),
name := "multi-tenant",
avroSource := new File("src/main/resources/avro"),
)
libraryDependencies += "org.apache.avro" % "avro" % "1.11.0"
the plugins.sbt:
addSbtPlugin("com.github.sbt" % "sbt-avro" % "3.4.0")
// Java sources compiled with one version of Avro might be incompatible with a
// different version of the Avro library. Therefore we specify the compiler
// version here explicitly.
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.0"
When building in IntelliJ (top-right green hammer button), no sources get generated. I have also tried writing compile
in the sbt console with the same result.
Here are some logs which appear when I first start up the sbt console in IntelliJ. It may contain some clues:
[info] welcome to sbt 1.5.8 (Oracle Corporation Java 11.0.11)
[info] loading global plugins from /home/sahand/.sbt/1.0/plugins
[info] loading settings for project multi-tenant-build from plugins.sbt,idea.sbt ...
[info] loading project definition from /home/sahand/multi-tenant/project
[warn] Unrecognized repository Scala Plugin Bundled Repository, ignoring it
[info] loading settings for project root from build.sbt ...
[info] set current project to multi-tenant (in build file:/home/sahand/multi-tenant/)
[warn] there's a key that's not used by any other settings/tasks:
[warn]
[warn] * root / avroSource
[warn] +- /home/sahand/multi-tenant/build.sbt:10
[warn]
[warn] note: a setting might still be used by a command; to exclude a key from this `lintUnused` check
[warn] either append it to `Global / excludeLintKeys` or call .withRank(KeyRanks.Invisible) on the key
[info] Defining Global / ideaPort
[info] The new value will be used by Compile / compile, Test / compile
[info] Reapplying settings...
[info] set current project to multi-tenant (in build file:/home/sahand/multi-tenant/)
Note the warning about the avroSource
setting not being used. Maybe that is why it cannot generate the sources for me? It might simply not find the Avro source files. How can I fix the issue and get my generated Scala classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sbt-avro 项目旨在生成Java类。如果要生成Scala类,建议您查看 sbt-avrohugger 。
在使用SBT-AvroHugger之类的项目结构中,您的build.sbt可能会这样做
,请记住导入插件。
sbt-avro project is meant to generate Java classes. If you want Scala classes to be generated, I suggest looking at sbt-avrohugger.
In a project structure like yours using sbt-avrohugger, your build.sbt may look like
To do that, remember to import the plugin.