首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >intelliJ IDEA对sbt不可变的支持

intelliJ IDEA对sbt不可变的支持
EN

Stack Overflow用户
提问于 2017-03-02 23:59:29
回答 1查看 607关注 0票数 2

当使用带IDEA和sbt的java sbt库时,编译和运行代码可以正常工作,但是编辑器会给出“无法解析符号.”。“解决不了方法.”使用生成的类时出错。

下面的建立IDE的文档对于Maven很好,但是不能解决sbt的问题。

我们如何使编辑器支持和代码完成工作在IDEA上使用sbt生成源?

EN

Stack Overflow用户

回答已采纳

发布于 2017-03-02 23:59:29

首先,遵循文献资料中的说明。

要在IntelliJ IDEA中配置注释处理,请使用对话框首选项>项目设置>编译器>注释处理器。

接下来,问题是sbt将生成的源文件放在target/scala-2.n/classes/our/package中。这是编译后的.class文件的目录,所以我们需要在其他地方生成源代码。编辑IDEA设置对我们没有帮助,因此我们需要通过添加以下内容来编辑build.sbt

代码语言:javascript
复制
// tell sbt (and by extension IDEA) that there is source code in target/generated_sources
managedSourceDirectories in Compile += baseDirectory.value / "target" / "generated_sources"
// before compilation happens, create the target/generated_sources directory
compile in Compile <<= (compile in Compile).dependsOn(Def.task({
  (baseDirectory.value / "target" / "generated_sources").mkdirs()
}))
// tell the java compiler to output generated source files to target/generated_sources
javacOptions in Compile ++= Seq("-s", "target/generated_sources")

最后,我们需要通过删除目录上的排除,告诉我们不应该忽略target/中的所有内容。要么转到file > Project > Project > Modules,然后单击target目录并取消选择"Excluded“。或者,右击项目选项卡下的target目录,标记目录作为>取消排除。

此时,您应该看到编辑器支持正常工作,如果不是,运行sbt clean compile以确保生成源代码。

更新:在最近的sbt版本中,<<=语法已被删除,您可以将上面的第二个指令替换为

代码语言:javascript
复制
// before compilation happens, create the target/generated_sources directory
compile in Compile := (compile in Compile).dependsOn(Def.task({
  (baseDirectory.value / "target" / "generated_sources").mkdirs()
})).value
票数 4
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42568234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档