是否可以仅在编译测试源时添加Scala编译器插件?
当通过调用 SBT 添加编译器插件时addCompilerPlugin
然后添加库依赖项。相关方法有:
/** Transforms `dependency` to be in the auto-compiler plugin configuration. */
def compilerPlugin(dependency: ModuleID): ModuleID =
dependency.withConfigurations(Some("plugin->default(compile)"))
/** Adds `dependency` to `libraryDependencies` in the auto-compiler plugin configuration. */
def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
libraryDependencies += compilerPlugin(dependency)
问题归结为是否存在withConfigurations
这会导致插件仅在编译测试源时才位于类路径上。我试过Some("plugin->default(testCompile)")
没有成功。
回答我自己的问题:可以通过设置autoCompilerPlugins
为 false 并添加必要的-Xplugin=...
在测试配置中手动选择 Scalac 选项。这可以通过使用来完成Classpaths.autoPlugins
实用方法。
就我而言,我只想在测试期间激活 SemanticDB 编译器插件。这可以通过以下 SBT 设置来完成:
autoCompilerPlugins := false,
ivyConfigurations += Configurations.CompilerPlugin,
scalacOptions in Test ++= Classpaths.autoPlugins(update.value, Seq(), ScalaInstance.isDotty(scalaVersion.value)),
scalacOptions in Test += "-Yrangepos",
scalacOptions in Test += "-P:semanticdb:text:on",
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)