gpt4 book ai didi

scala - 如何从 AutoPlugin 修改 Compile 中的 sourceGenerators?

转载 作者:行者123 更新时间:2023-12-02 04:28:28 25 4
gpt4 key购买 nike

我正在使用新的 AutoPlugin 机制为 sbt 编写代码生成插件。我需要修改sourceGenerators in Compile设置,但当我从插件中执行此操作时,它不起作用。调用compile后,屏幕上没有打印任何内容。

但是,如果我采取 sourceGenerators in Compile <+= (mySourceGenerator in Compile) 行并将其移至build.sbt该项目突然sourceGenerators in Compile设置被修改,当我运行编译任务时,消息被写入屏幕。

我有什么遗漏的吗?插件代码在这里:

package net.lopezbobeda.plugin

import sbt._
import Keys._
import java.io.{ File, Writer }

object MyPlugin extends AutoPlugin {
// by defining autoImport, the settings are automatically imported into user's `*.sbt`
object autoImport {
// configuration points, like the built-in `version`, `libraryDependencies`, or `compile`
lazy val mySourceGenerator = taskKey[Seq[File]]("Generate")

// default values for the tasks and settings
lazy val baseXtendPluginSettings: Seq[Def.Setting[_]] = Seq(
mySourceGenerator in Compile := {
val s: TaskStreams = streams.value
s.log.info("Generating! " + sourceManaged.value)
Nil
},
sourceGenerators in Compile <+= (mySourceGenerator in Compile) // if I put this line in build.sbt everything works as expected.
)

}

override def trigger = allRequirements

import autoImport._

override val projectSettings = baseXtendPluginSettings


}

最佳答案

问题是 JVM 插件重置了 sourceGenerators 设置。解决办法就是添加:

override def requires = JvmPlugin

我在另一个问题中找到了解决方案:

How to generate sources in an sbt plugin?

关于scala - 如何从 AutoPlugin 修改 Compile 中的 sourceGenerators?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25158287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com