首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在从sourceGenerators编译时修改AutoPlugin?

如何在从sourceGenerators编译时修改AutoPlugin?
EN

Stack Overflow用户
提问于 2014-08-06 10:42:05
回答 1查看 474关注 0票数 2

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

但是,如果我将行sourceGenerators in Compile <+= (mySourceGenerator in Compile)移到项目的build.sbt中,那么sourceGenerators in Compile设置就会突然被修改,当我运行编译任务时,消息会被写到屏幕上。

有什么东西我错过了吗?插件的代码如下:

代码语言:javascript
复制
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


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-06 10:48:48

问题是JVM插件重置了sourceGenerators设置。解决方案只是添加:

代码语言:javascript
复制
override def requires = JvmPlugin

我在另一个问题中找到了解决办法:

How to generate sources in an sbt plugin?

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25158287

复制
相关文章

相似问题

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