使用 sbt 编译 Java 注释 [英] Compiling Java annotations with sbt

查看:37
本文介绍了使用 sbt 编译 Java 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 $PROJECT/src/main/java 下创建了 Java 注释(因为我需要运行时保留)和我的 Scala 代码,它在 $PROJECT/src 下使用这些 java 注释/main/scala.这样创建的 Java 注释也使用 Java ENUM 作为它的值.

I've created Java annotations (since I need run time retention) under $PROJECT/src/main/java and my scala codewhich uses these java annotations us under $PROJECT/src/main/scala. The Java annotation thus created also makes use of a Java ENUM as it's value.

如果我编译项目,那么 sbt 似乎不会首先编译 Java 注释,并且在注释中每次使用枚举时都会出错.如果我在 Scala 代码的注释中注释掉 Java 枚举的所有用法并进行编译,取消注释枚举用法并再次编译,一切正常.

If I compile the project then sbt doesn't seem to compile the Java annotations first and errors out on each usage of the enum in annotations. If I comment out all usages of the Java enum in annotations in scala code and do a compile, uncomment enum usage and compile again it all works fine.

在尝试编译 scala 代码之前,如何确保 sbt 编译我的 java 注释和枚举(即 $PROJECT/src/main/java)?

How do I ensure that sbt compiles my java annotations and enum (i.e. $PROJECT/src/main/java) before attempting to compile scala code when doing a clean build?

我有一个基本的 build.sbt 并且正在使用 sbt 0.11.2

I have a bare bones build.sbt and am using sbt 0.11.2

推荐答案

一些好消息:这是 一个已知问题并已解决.

Some good news: This is a known issue and has been resolved.

一些坏消息:它已在 2.10 中解决,并且修复程序可能不会向后移植到 2.9.3(在问题线程中引用 Paul Phillips):

Some bad news: It's resolved in 2.10 and the fix may not be backported to 2.9.3 (quoting Paul Phillips in the issue thread):

我已将其标记为向后移植,这不是保证;我不现在有时间做,但我希望在不久的将来.

I've tagged this for backporting, which is not a guarantee; I don't have time to do it right now but I expect to in the near future.

一些好消息:如果您坚持使用 2.10 之前的版本并且您的 Java 源代码不依赖于您的 Scala 源代码,您可以将以下内容添加到您的 build.sbt 中,一切都很好:

Some good news: If you're stuck on pre-2.10 and your Java sources don't depend on your Scala sources, you can just add the following to your build.sbt and all is well:

compileOrder := CompileOrder.JavaThenScala

一些坏消息:如果您坚持使用 2.10 之前的版本并且您的 Java 源代码确实依赖于您的 Scala 源代码,那么我很确定您不走运,并且注释-编译-取消注释技巧可能是您的最好的选择.

Some bad news: If you're stuck on pre-2.10 and your Java sources do depend on your Scala sources, I'm pretty sure you're out of luck, and the comment-compile-uncomment trick is probably your best bet.

这篇关于使用 sbt 编译 Java 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆