My Scala 3 code starts with
#main def primer(): Unit = {
. . .
}
and when I use
% sbt run
It runs fine...
% sbt run
[info] welcome to sbt 1.6.2 (Oracle Corporation Java 11.0.13)
[info] loading global plugins from /Users/eric.kolotyluk/.sbt/1.0/plugins
[info] loading project definition from /Users/eric.kolotyluk/git/autonomous-iam/poc/fp-laboratory/project
[info] loading settings for project root from build.sbt ...
[info] set current project to fp-laboratory (in build file:/Users/eric.kolotyluk/git/autonomous-iam/poc/fp-laboratory/)
[info] running com.forgerock.fp.laboratory.primer
Primer running... with 11.0.13+10-LTS-370
Note: SBT believes it is running com.forgerock.fp.laboratory.primer
But, if I try
% sbt "runMain com.forgerock.fp.laboratory.primer"
[info] welcome to sbt 1.6.2 (Oracle Corporation Java 11.0.13)
[info] loading global plugins from /Users/eric.kolotyluk/.sbt/1.0/plugins
[info] loading project definition from /Users/eric.kolotyluk/git/autonomous-iam/poc/fp-laboratory/project
[info] loading settings for project root from build.sbt ...
[info] set current project to fp-laboratory (in build file:/Users/eric.kolotyluk/git/autonomous-iam/poc/fp-laboratory/)
[info] running com.forgerock.fp.laboratory.primer
Primer running... with 11.0.13+10-LTS-370
Exception in thread "sbt-bg-threads-1" java.lang.NoClassDefFoundError: org/apache/spark/sql/SparkSession
at com.forgerock.fp.laboratory.Primer$package$.primer(Primer.scala:30)
So, clearly, run and runMain do not do the same thing.
Is there a way to make runMain do the right thing?
Is this caused by some weirdness with the Scala 3 #main annotation?
Related
I have build.properties file in the project with the following line:
sbt.version=1.2.8
build.properties file is in the same folder as build.sbt file.
But when I enter the command "sbt about", it reports 1.0.3. Following is the actual output of the command:
/Users/kale> sbt about
[info] Loading settings from idea.sbt ...
[info] Loading global plugins from /Users/kale/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from
/Users/kale/workspace/gr8Project/myapp/project
[info] Loading settings from build.sbt ...
[info] Set current project to myapp (in build
file:/Users/kale/workspace/gr8Project/myapp/)
[info] This is sbt 1.0.3
[info] The current project is
{file:/Users/kale/workspace/gr8Project/myapp/}myapp 0.1-SNAPSHOT
[info] The current project is built against Scala 2.12.8
[info] Available Plugins: sbt.plugins.IvyPlugin,
sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin,
sbt.plugins.JUnitXmlReportPlugin,
sbt.plugins.Giter8TemplatePlugin, sbtassembly.AssemblyPlugin,
com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin,
com.lucidchart.sbt.scalafmt.ScalafmtPlugin,
com.lucidchart.sbt.scalafmt.ScalafmtSbtPlugin,
scoverage.ScoverageSbtPlugin,
net.virtualvoid.sbt.graph.DependencyGraphPlugin,
sbtdocker.DockerPlugin, Build, Docker
[info] sbt, sbt plugins, and build definitions are using Scala
2.12.4
How can I change sbt version to 1.2.8?
your project structure should be <root>/project/build.properties, and then you should change the sbt version property (see https://github.com/pedrorijo91/play-slick3-steps/blob/master/project/build.properties as an example)
Use sbt about to know the version in use.
On a Windows machine, I am running through the getting started tutorial here: https://www.scala-sbt.org/1.x/docs/sbt-by-example.html
I am able to start the sbt shell and compile but using the run command just hangs and I am forced to Ctrl-C to exit sbt.
Running scala against the JAR file directly also works as expected.
Sample output is the following:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from S:\foo-build\project
[info] Loading settings for project foo-build from build.sbt ...
[info] Set current project to foo-build (in build file:/S:/foo-build/)
[info] sbt server started at local:sbt-server-8c6933abcb6848dbd242
sbt:foo-build> about
[info] This is sbt 1.2.8
[info] The current project is ProjectRef(uri("file:/S:/foo-build/"), "foo-build") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.7
[info] Available Plugins
[info] - sbt.ScriptedPlugin
[info] - sbt.plugins.CorePlugin
[info] - sbt.plugins.Giter8TemplatePlugin
[info] - sbt.plugins.IvyPlugin
[info] - sbt.plugins.JUnitXmlReportPlugin
[info] - sbt.plugins.JvmPlugin
[info] - sbt.plugins.SbtPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.7
sbt:foo-build> compile
[success] Total time: 0 s, completed Feb 7, 2019 4:40:45 PM
sbt:foo-build> run
Terminate batch job (Y/N)? Y
This is enough of an answer for my own purposes.
I was able work around this issue by adding a line to my build.sbt file. After adding ThisBuild / scalaVersion := "2.12.8" I was able to use the run command. Following the tutorial linked in the main question I would not expect to have to do this but perhaps someone could shed some light.
I have installed sbt 1.0.2 and tried building the "hello project", but it hangs after done compilation.
I waited for 2 hours and it does not complete. what am I missing here?
HOSTPC:IdeaProjects XYZ2017$ sbt new sbt/scala-seed.g8
[info] Loading settings from plugins.sbt ...
[info] Loading global plugins from /Users/XYZ2017/.sbt/1.0/plugins
[info] Set current project to ideaprojects (in build file:/Users/XYZ2017/IdeaProjects/)
A minimal Scala project.
name [Scala Seed Project]: hello
Template applied in ./hello
HOSTPC:IdeaProjects XYZ2017$ ls
hello
HOSTPC:IdeaProjects XYZ2017$ cd hello/
HOSTPC:hello XYZ2017$ sbt
[info] Loading settings from plugins.sbt ...
[info] Loading global plugins from /Users/XYZ2017/.sbt/1.0/plugins
[info] Loading project definition from /Users/XYZ2017/IdeaProjects/hello/project
[info] Updating {file:/Users/XYZ2017/IdeaProjects/hello/project/}hello-build...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/XYZ2017/IdeaProjects/hello/project/target/scala-2.12/sbt-1.0/classes ...
[info] Done compiling.
I'm trying to get a clue about Scala/SBT and was walking through http://www.scala-sbt.org/0.13/docs/Hello.html
The first step went well...I've got a directory called "hello" that has the result of $ sbt new sbt/scala-seed.g8 in it.
At the 2nd step, "Running your app", the wheels come off.
$ sbt
[info] Loading project definition from /Users/robert.kuhar/dev/Hello/project
[info] Set current project to Hello (in build file:/Users/robert.kuhar/dev/Hello/)
> run
[info] Compiling 1 Scala source to /Users/robert.kuhar/dev/Hello/target/scala-2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.1. Compiling...
[info] Resolving org.scala-sbt#interface;0.13.13 ...
[trace] Stack trace suppressed: run last compile:compileIncremental for the full output.
[error] (compile:compileIncremental) java.lang.reflect.InvocationTargetException
[error] Total time: 1 s, completed Mar 9, 2017 3:34:03 PM
>
The output of the run last compile:compileIncremental is greek to the eyes of a noobie...
...
[info] Resolving org.scala-sbt#interface;0.13.13 ...
java.lang.VerifyError: Uninitialized object exists on backward branch 209
Exception Details:
Location:
scala/collection/immutable/HashMap$HashTrieMap.split()Lscala/collection/immutable/Seq; #249: goto
Reason:
Error exists in the bytecode
...
I'm off the track, in the weeds, and in search of a clue.
I don't know if any of this version stuff matters, but I'm OSX Sierra with a 1.8 JDK and 0.13.13 SBT. There is a Scala 2.12.1 on this machine.
$ sbt sbtVersion
[info] Loading project definition from /Users/robert.kuhar/dev/Hello/project
[info] Set current project to Hello (in build file:/Users/robert.kuhar/dev/Hello/)
[info] 0.13.13
$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ scala -version
Scala code runner version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
How do I get the "SBT Hello, World" to run on my dev box?
Here's a way to do it without the sbt new plugin.
Create the following dirs and file in a directory Hello:
├── build.sbt
└── src
└── main
└── scala
└── Hello.scala
Put this in Hello.scala
object Hello extends App{
println("Hello")
}
In Hello/build.sbt add this line:
scalaVersion := "2.11.8
Run it with run
/tmp/Hello $ sbt [16:40:38]
[info] Loading global plugins from /home/brian/.sbt/0.13/plugins
[info] Set current project to hello (in build file:/tmp/Hello/)
> run
[info] Compiling 1 Scala source to /tmp/Hello/target/scala-2.11/classes...
[info] Running Hello
Hello
...
I've had "mixed" results with the g8/giterate templates in the past but that may or may not be your issue. I've used https://github.com/sbt/sbt-fresh and that worked well. If your completely new to Scala and SBT the above code and build setup should get you started.
My build is simple:
lazy val stampleWebProject = play.Project("stample-web", appVersion, appDependencies,path = file("stample-web"))
.dependsOn(stampleCoreProject,stampleSearchProject)
.aggregate(stampleCoreProject,stampleSearchProject)
lazy val stampleCoreProject = Project(id = "stample-core",base = file("stample-core"))
lazy val stampleSearchProject = Project(id = "stample-search",base = file("stample-search"))
All these projects have a build.sbt file with dependencies, without any scala build (which would be ignored as far as I know)
When I start SBT (12.4), I get the following:
[info] Set current project to stample-core (in build file:/home/sebastien/Bureau/Stample/)
> projects
[info] In file:/home/sebastien/Bureau/Stample/
[info] * stample-core
[info] stample-search
[info] stample-web
> project stample-search
[info] Set current project to stample-search (in build file:/home/sebastien/Bureau/Stample/)
> projects
[info] In file:/home/sebastien/Bureau/Stample/
[info] stample-core
[info] * stample-search
[info] stample-web
> project stample-core
[info] Set current project to stample-core (in build file:/home/sebastien/Bureau/Stample/)
> projects
[info] In file:/home/sebastien/Bureau/Stample/
[info] * stample-core
[info] stample-search
[info] stample-web
> project stample-web
[info] Set current project to stample-search (in build file:/home/sebastien/Bureau/Stample/)
[stample-search] $ projects
[info] In file:/home/sebastien/Bureau/Stample/
[info] stample-core
[info] stample-search
[info] * stample-web
[stample-search] $ compile
[info] Updating {file:/home/sebastien/Bureau/Stample/}stample-core...
[info] Resolving org.slf4j#slf4j-api;1.6.6 ...
[info] Done updating.
[info] Updating {file:/home/sebastien/Bureau/Stample/}stample-web...
[error] a module is not authorized to depend on itself: stample-search#stample-search_2.10;1.0
[error] (stample-web/*:update) java.lang.IllegalArgumentException: a module is not authorized to depend on itself: stample-search#stample-search_2.10;1.0
[error] Total time: 1 s, completed 26 août 2013 21:57:45
I do not understand some stuff here:
How is choosen the project in which we are by default. I've seem documentation was added in SBT 13.0 but did not see it in the 12.4 multibuild documentation.
How comes I type project stample-web and it tells me I'm in stample-search
Why is there a special display in my sbt console for the project I'm in (stample-web or stample-search, I don't really know...) (this appears here: [stample-search] $ compile, is this relative to play projects?
Why it can't compile stample-search, since it doesn't depend on itself in my build (I suspect it tries to compile the web project but there's a naming problem or something?
Is this an SBT bug. If so, is it possible to use the new 13.0 version with Play framework?
Eugene Yokota is right: I have a conflict in the stample-web folder, which was set the stample-web name in the scala build, but it has a wrong build.sbt in the folder which has name := stample-search