Hi Everyone,
I have some code that uses the scala.tools.nsc.io.File class to append some output to a file named log.txt.
Scalac successfully compiles it, but sbt fails.
Can someone shed some light on why sbt would fail ?
Using : scala 2.11.8
sbt 0.13.12
OS: RedHat 6.3
$ cat foo.scala
object Classes {
def main(args: Array[String]) {
scala.tools.nsc.io.File("log.txt").appendAll("line1\n")
scala.tools.nsc.io.File("log.txt").appendAll("line2\n")
}
}
cat build.sbt
lazy val root = (project in file(".")).
settings(
name := "mccs-common",
version := "0.17-SNAPSHOT"
// scalaHome := Some(file("/usr/local/share/scala-2.11.8")),
// scalaVersion := "2.11.8"
)
$ sbt
[info] Set current project to mccs-common (in build file:/home/temp/workspace/ws-test/)
> compile
[info] Updating {file:/home/temp/workspace/ws-test/}root...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/temp/workspace/ws-test/target/scala-2.10/classes...
[error] /home/temp/workspace/ws-test/foo.scala:4: object tools is not a member of package scala
[error] scala.tools.nsc.io.File("log.txt").appendAll("line1\n")
[error] ^
[error] /home/temp/workspace/ws-test/foo.scala:5: object tools is not a member of package scala
[error] scala.tools.nsc.io.File("log.txt").appendAll("line2\n")
[error] ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Sep 28, 2016 2:40:26 PM
Same code compiles and runs successfully using scalac.
$ scalac foo.scala
$ scala Classes
$ cat log.txt <- resulting file
line1
line2
Google found some posts claiming that this class is an unpublished API.
I
would hate to switch build tools, just because a developer decided to use an unsanctioned API.
Thank you.
Henry