sbt interview questions
Top sbt frequently asked interview questions
I am diving into Scala and noticed sbt. I have been quite happy with Gradle in java/groovy projects, and I know there's a scala plugin for Gradle.
What could be good reasons to favour sbt over Gradle in a Scala project?
Source: (StackOverflow)
I'm having problems with a maven dependency which is in my local respository.
SBT can't find it. Already set log level to debug, but not getting anything new.
The files are in the repository. I copy paste paths from the console to file explorer and they are there.
The output:
[debug] trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom
[debug] tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom
[debug] Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.pom
[debug] trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar
[debug] tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar
[debug] Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.jar
[debug] Local Maven Repository: no ivy file nor artifact found for com.twitter#naggati;2.0.0
Edit: I added the path using scala file in project/build like described in http://code.google.com/p/simple-build-tool/wiki/LibraryManagement
"sbt can search your local Maven repository if you add it as a repository:"
val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"
That made sbt look in the local repository. Before it didn't.
So the scala file looks like this:
import sbt._
class Foo(info: ProjectInfo) extends DefaultProject(info) {
val mavenLocal = "Local Maven Repository" at "file://c:/Users/userz/.m2/repository"
}
(I hardcoded Path.userHome to exclude possible error reason. As expected it didn't change anything).
Source: (StackOverflow)
I am using IntelliJ IDEA 13.1.4 and also tried the latest release 14.
Running SBT I get the following error:
Error:Cannot determine Java VM executable in selected JDK
I have JDK 1.7 installed on my machine and on PATH.
In the logs (~/Library/Logs/IntelliJIdea14/idea.log
on MacOS) there's the following stack trace:
2014-11-03 11:22:05,054 [4896641] WARN - nal.AbstractExternalSystemTask - Cannot determine Java VM executable in selected JDK
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot determine Java VM executable in selected JDK
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
at scala.Option.getOrElse(Option.scala:120)
at org.jetbrains.sbt.project.SbtExternalSystemManager$.executionSettingsFor(SbtExternalSystemManager.scala:96)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
at org.jetbrains.sbt.package$$anon$3.fun(package.scala:29)
at org.jetbrains.sbt.package$$anon$3.fun(package.scala:28)
at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.getExecutionSettings(ExternalSystemApiUtil.java:590)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:201)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:178)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.doInvoke(ExternalSystemFacadeManager.java:133)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager$MyHandler.invoke(ExternalSystemFacadeManager.java:270)
at com.sun.proxy.$Proxy57.getResolver(Unknown Source)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:48)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.execute(ExternalSystemUtil.java:475)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3$1.run(ExternalSystemUtil.java:543)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:609)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$7.run(ProgressManagerImpl.java:410)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$3.run(ProgressManagerImpl.java:194)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.a(ProgressManagerImpl.java:281)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:233)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:181)
at com.intellij.openapi.application.impl.ApplicationImpl$10$1.run(ApplicationImpl.java:640)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:405)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
What can be the reason for this?
Source: (StackOverflow)
Which build tool is the best for Scala? What are the pros and cons of each of them? How to I determine which one of them to use in a project?
Source: (StackOverflow)
How do I check which version of sbt I'm running?
I have the bash file set up that uses sbt-launch.jar
, and it works, but
$ sbt version
only shows the "project version" (0.1) and
$ sbt --version
does nothing.
Source: (StackOverflow)
What's the easiest way to debug Scala code managed by sbt using IntelliJ's built-in debugger? The documentation from "RunningSbt" from sbt's google code site lists commands for running the main class for a project or the tests, but there seem to be no commands for debugging.
Follow-up question: what's the easiest way to attach IntelliJ's debugger to Jetty when using sbt's jetty-run command?
Source: (StackOverflow)
I know that a single test can be ran by running, in sbt,
test-only *class -- -n Tag
Is there a way of telling sbt/scalatest to run a single test without tags? For example:
test-only *class -- -X 2
it would mean "run the second test in the class. Whatever it is". We have a bunch of tests and no one bothered to tag them, so is there a way to run a single test without it having a tag?
Source: (StackOverflow)
I would like to disable the color escape codes logged from sbt/play. Is this possible? And if it is, is there a way to do it without making changes to the config - i.e. via a command line switch or system property.
Source: (StackOverflow)
As you know, SBT is compatible with Maven in some way -- SBT recognizes simple Maven POMs and can use dependencies and repositories specified in them. However, SBT wiki says that, if inline dependency is specified in SBT project definition, POM will be ignored (so using both in this case is impossible):
Maven and Ivy configurations (pom.xml
and ivy.xml) are ignored when inline
dependency declarations are present.
Does anyone know, if any kind of converter from Maven POM to SBT project definition exists (translating POM's XML into project definition Scala code)? I'm considering writing such script (that will help to migrate my old Scala/Maven projects to SBT), but want to know first, if this functionality already exists.
Source: (StackOverflow)
I am starting to use sbt build my Scala code (and handle dependencies). As far as I know if I use
$ sbt run <args>
on the command line this will run the main class of the main project.
Is it possible to 'run' within any other project from the command line, i.e. not in the interactive session mode? (I'm thinking about something that might look like $ sbt project <proj> run <args>
or whatever...)
What I would do in interactive mode is this:
$ sbt
> project <projectname>
> run <args>
This seems to be straightforward enough, but I can not find any documentation describing this behavior. Hints would be much appreciated...
Source: (StackOverflow)
How do you terminate a run in SBT without exiting?
I'm trying CTRL+C but it exits SBT. Is there a way to only exit the running application while keeping SBT open?
Source: (StackOverflow)
I started to learn Scala and almost in every tutorial I see a build.sbt
file which describes project settings. But now I have installed giter8
and created a project from template. And generated project from template missed build.sbt
file, but it have build.scala
(which seems used for same purposes, but it is more flexible).
So what is the difference between build.sbt
and build.scala
?
Which is more preferred and why?
Source: (StackOverflow)
I'm developing several modules with dependencies among them, and would like to work with them all together in one IDEA project. I'm using sbt-idea to generate IDEA projects from the sbt build definitions, which works great for individual projects. In the multiple-module case, however, the things I've tried so far don't quite work:
Use sbt-idea to generate an IDEA .iml file for each module independently; then create a master IDEA project from scratch an add those modules to it. This makes the module sources all editable in the same window, but the dependencies among them are not tracked (so trying to navigate from some source within the foo project to something in bar takes me to the imported library version of bar, not the local sources).
Use sbt multi-project builds (aka subprojects), where the parent project's Build.scala contains things like:
lazy val foo = Project(id = "foo", base = file("foo"))
lazy val bar = Project(id = "bar", base = file("bar")) dependsOn(foo)
This almost works, in that sbt-idea generates a master IDEA project with the dependencies among the subprojects tracked. There are however two caveats:
- It seems to be an sbt restriction that the subprojects must live in subdirectories of the master project (i.e.,
file("../foo")
is not allowed). This is not really what I want (what if a module--such as a "utils" or "commons" package--is used in two different master projects?) but I can live with it.
- One of my subprojects has its own subprojects; I'm not sure whether sbt itself deals with these nested projects correctly, but in any case they are ignored by sbt-idea. Obviously I need nested subprojects to be included recursively in the master project.
To summarize: I'd like to collect modules which may already have subprojects into one big IDEA project with tracked dependencies for convenient editing. How can I do it? Thanks!
Source: (StackOverflow)
(This is a follow up to sbt not creating projects correctly. The question wasn't answered.)
Basically, that question says "I don't know how to create a project under the new sbt. With the old one, I just ran sbt
in a new folder and there was a guided wizard that led me through the setup."
The accepted answer does not explain how to create a new project, it just points to the documentation, which also doesn't explicitly say how to create a new project -- only how to write a build.sbt
file.
So I tried first writing a build.sbt
and then running sbt
in the directory with the build.sbt
file, but I still don't see a src
directory to work with.
Could someone post a simple step-by-step (I'm assuming there are like 3 steps at most) guiding how to create a new project under sbt 0.10.X?
Source: (StackOverflow)