我喜欢scalacOptions在顶级定义(例如,暂时忽略项目轴):
scalacOptions += "-Ywarn-unused-import"
Run Code Online (Sandbox Code Playgroud)
但后来我意识到这太严格了console.所以我试着设置:
scalacOptions in console ~= (_ filterNot (_ == "-Ywarn-unused-import"))
Run Code Online (Sandbox Code Playgroud)
但这不起作用(在REPL中仍然有致命的警告).
我曾经inspect尝试理解为什么:
> inspect console
[info] Task: Unit
[info] Description:
[info] Starts the Scala interpreter with the project classes on the classpath.
[info] Provided by:
[info] {file:/a/}b/compile:console
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:261
[info] Dependencies:
[info] compile:console::compilers
[info] compile:console::initialCommands
[info] compile:console::fullClasspath
[info] compile:console::taskTemporaryDirectory
[info] compile:console::scalaInstance
[info] compile:console::streams
[info] compile:console::cleanupCommands
[info] compile:console::scalacOptions
[info] Delegates:
[info] compile:console
[info] *:console
[info] {.}/compile:console
[info] …Run Code Online (Sandbox Code Playgroud) 我想知道如何配置Dropwizard来记录JSON响应.
我经常想要添加sbt-dependency-graph-sugar到当前会话中.我目前的做法是:
> reload plugins
> set addSbtPlugin("com.gilt" % "sbt-dependency-graph-sugar" % "0.7.4")
> session save
> reload return
> dependencyTree
Run Code Online (Sandbox Code Playgroud)
然后在以后恢复文件系统上的更改.有没有办法在更少的步骤中执行此操作,而无需更改构建文件?
$ sbt --version
sbt launcher version **0.13.8**
Run Code Online (Sandbox Code Playgroud)
$ sbt console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Run Code Online (Sandbox Code Playgroud)
如何配置(或更新)sbt以便sbt console使用最新的Scala版本2.11.6?
有人可以在这个神秘的习语中解释每个compile和Compile意味着什么:
compile in Compile <<= (compile in Compile).dependsOn(Def.task {
println("task is running") // or whatever code here in the body
})
Run Code Online (Sandbox Code Playgroud) 给定Printer具有依赖类型的类型类Show[A]:
trait Printer {
type Show[A]
def show[A](x: A)(implicit z: Show[A]): String
}
object Printer {
// the intent here is this is the dumb fallback
// and a user can have a better alternative in scope
implicit val dumbPrinter: Printer = new Printer {
type Show[A] = DummyImplicit
def show[A](x: A)(implicit z: DummyImplicit): String = x.toString
}
}
Run Code Online (Sandbox Code Playgroud)
我如何编码此方法:
def r[A](x: A)(implicit printer: Printer, show: printer.Show[A]): String =
printer.show(x)(show)
Run Code Online (Sandbox Code Playgroud)
我一直在努力调整@ MilesSabin的主要工作代码https://gist.github.com/milessabin/cadd73b7756fe4097ca0和@ TravisBrown的博客文章https://meta.plasm.us/posts/2015/07/11/ …
在我们的Play项目中,我们遇到了这个问题.
当我们运行我们的javascript测试时,它会触发scala源代码的编译.
所有javascripts测试都在,test/assets并且此路径内的任何更改都不应触发源的编译.
这意味着此文件夹在某处被称为源目录.我试图看到哪个sbt属性可以引用这个文件夹,但我没有找到任何.
任何人都可以提供一些线索,如何在这个文件夹中的文件被更改时阻止编译触发?
我有以下测试代码:
public interface Container<I> {
public void addClass(Class<?> clazz);
}
public class MyContainer implements Container {
public void addClass(Class<?> clazz) {}
}
Run Code Online (Sandbox Code Playgroud)
尝试编译这两个类时,我收到以下错误:
MyContainer.java:1:MyContainer不是抽象的,不会覆盖Container中的抽象方法addClass(java.lang.Class)
如果我在MyContainer中向Container接口添加一个类型(例如<Object>),我就不会收到错误.
问题是我将类型参数引入到Container,它是公共API的一部分,因此为了兼容性,我不能让所有实现类都无法编译.
有人有主意吗?这是类型擦除问题吗?有解决方法吗?
使用Build.scala向MANIFEST.MF添加自定义键值对似乎不起作用.这是我的代码:
import sbt._
import Keys._
import java.util.Date
object Build extends Build {
packageOptions in (Compile, packageBin) +=
Package.ManifestAttributes( "Build" -> "true" )
}
Run Code Online (Sandbox Code Playgroud)
当我添加:
packageOptions in (Compile, packageBin) +=
Package.ManifestAttributes( "Sign" -> "true" )
Run Code Online (Sandbox Code Playgroud)
到我的build.sbt然后只Sign到达我的MANIFEST.MF.有什么想法吗?
接下来,当x.toString失败时,ScalaRunTime.stringOf(x)如何失败?, 怎么
x.toString
Run Code Online (Sandbox Code Playgroud)
不同于
(x: Any).toString
Run Code Online (Sandbox Code Playgroud)
还有,怎么样
"" + x
Run Code Online (Sandbox Code Playgroud)
示例REPL会话:
> scala -cp joda-time-2.3.jar
Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val dt = new org.joda.time.DateTime
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString …Run Code Online (Sandbox Code Playgroud) sbt ×6
scala ×3
java ×2
dropwizard ×1
generics ×1
http ×1
inheritance ×1
jersey ×1
manifest.mf ×1
overloading ×1
overriding ×1
type-erasure ×1