【问题标题】:Annotation Processor output path sbt?注释处理器输出路径 sbt?
【发布时间】:2020-11-24 19:11:02
【问题描述】:

有没有办法在sbt中设置Annotation处理器的输出路径?

目前它将文件生成到:

target/scala-2.11/classes

不过我更喜欢

target/scala-2.11/src_managed

【问题讨论】:

标签: sbt


【解决方案1】:

类似

// in build.sbt:

// create managed source directory before compile
compile in Compile <<= (compile in Compile) dependsOn Def.task { (managedSourceDirectories in Compile).value.head.mkdirs() },

// tell the java compiler to output generated source files to the managed source directory
javacOptions in Compile ++= Seq("-s", (managedSourceDirectories in Compile).value.head.getAbsolutePath),

【讨论】:

  • 我不得不将其更改为javacOptions in Compile ++= Seq("-s", (managedSourceDirectories in Compile).value.head.getAbsolutePath),但它确实有效。感谢您的评论!
  • 谢谢我刚刚忽略了你的完整回答。
  • 顺便说一句,虽然这有效,但是在“更清洁”的环境中(即詹金斯我们得到以下内容:```java.lang.IllegalStateException:找不到目录:(发出)/target/scala- 2.11/src_managed/main```有什么办法解决吗?
  • 先创建目录,如compile &lt;&lt;= compile dependsOn Def.task { (managedSourceDirectories in Compile).value.head.mkdirs() }
  • 实际上这会给我一个错误:Reference to undefined setting: *:compile from *:compile
【解决方案2】:

配置sourceManaged而不是managedSourceDirectories更符合人体工程学。

build.sbt 中添加到sbt 模块的设置:

Compile / javacOptions ++= Seq("-s", (Compile / sourceManaged).value.getAbsolutePath)

您也可以将此插件放到project 文件夹中

package custom.sbt

import sbt.{Def, _}
import sbt.Keys._

object Compiler extends AutoPlugin {
  override def trigger = allRequirements

  override def buildSettings: Seq[Def.Setting[_]] = Seq(
    Compile / javacOptions ++= Seq("-source", "11", "-target", "11"),
    scalacOptions ++= Seq(
      "-target:11"              // Target JRE 11
    )
  )

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    Compile / javacOptions ++= Seq("-s", (Compile / sourceManaged).value.getAbsolutePath)
  )
}

【讨论】:

    【解决方案3】:

    在 sbt 0.13.15

    compile := ((compile in Compile) dependsOn Def.task {
          (sourceManaged in Compile).value.mkdirs()
        }).value,
    
    javacOptions in Compile ++= Seq("-s", s"${sourceManaged.value}/main")
    

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      相关资源
      最近更新 更多