Imagine I would like to define a sbt task which is the equivalent of
sbt runDev "-Dconfig.resource=dev.conf"
and then call it via
sbt runDev
runDev is custom run-task in that case. How would the part of my build.sbt look like? Ideally I would like to do something like
javaOptions in runDev += "config.resource=application-dev.conf"
I found a solution myself
fork in runDev := true
javaOptions in runDev ++= Seq("-Dconfig.resource=dev.conf")
The fork is important otherwise it wont start a new JVM with the corresponding java options!
Related
I use SBT / Console as a prototyping tool and therefore don't want to start with a pre-defined build.sbt file.
What I want to do is to run the sbt tool and then modify the libraryDependencies setting. then run console and go and use my newly imported library. If I need something more. I can exit the console and import more stuff and then come back in the console.
is this possible? or should I always start with a predefined build.sbt file?
set libraryDependencies += group % art % version
I understand ammonite is good at this as well
I want to change the sbt.ivy.home java option in my build.sbt file. I tried:
javaOptions := Seq("-Dsbt.ivy.home=c:/ivy2/")
But it doesn't work.
It work well on the command line:
sbt update -Dsbt.ivy.home=c:/ivy/
For Ivy home, you can set it via ivyPaths setting.
I am using the sbt revolver plugin to drive a vert.x scala project.
Currently I manually enter the following commands in sbt:
set mainClass in Revolver.reStart := Some("org.vertx.java.platform.impl.cli.Starter")
~re-start run scala:com.something.myClass
How could this be delegated to the build.sbt file, such that I can just run ~re-start in sbt, rather than those two commands every time?
It seems revolver has all the relevant configuration flexibility for that, but the sbt configuration language/conventions elude me and I failed to fiddle build.sbt to that effect.
You can add your settings to the build.sbt. It is rather simple, if you do set <whatever-here>, you can drop set and add it to the build.sbt directly.
For example, the build.sbt for your example would look like this.
build.sbt
Revolver.settings
mainClass in Revolver.reStart := Some("org.vertx.java.platform.impl.cli.Starter")
Revolver.reStartArgs := Seq("run", "scala:com.something.myClass")
The list of settings you can use is in the original link of yours, there are even some examples if you look down below.
When I compile Scala code, by running sbt compile, SBT says:
$ sbt compile
...
[warn] there were 5 deprecation warnings; re-run with -deprecation for details
...
How do I do that? (From within SBT?)
sbt shell
While in sbt shell (if you don't want to change your build.sbt):
$ sbt
> set ThisBuild/scalacOptions ++= Seq("-unchecked", "-deprecation")
> compile
> exit
Due to in ThisBuild, set applies the settings to all sub-projects, as well.
Command Line
You could also run the above as a single command on command line.
sbt '; set ThisBuild/scalacOptions ++= Seq("-unchecked", "-deprecation") ; compile'
The trick is to use ; (semicolons) to separate commands and ' (ticks) to include all ;-separated commands as a single argument to sbt.
sbt < 1.x
Instead of ThisBuild/scalacOptions use scalacOptions in ThisBuild
scalacOptions := Seq("-unchecked", "-deprecation")
Add this setting to your build.sbt, and, if you have a multi-module project, add it to every project's settings.
As times flows new solutions are emerged. So, now you could re-run the scala compiler without issuing entire project rebuild.
You need to install ensime-sbt plugin:
addSbtPlugin("org.ensime" % "sbt-ensime" % "1.0.0")
After that you could use the ensimeCompileOnly task to compile single file. SBT allows per tasks settings configuration, so you could change for that tasks only:
set scalacOptions in (Compile, EnsimeKeys.ensimeCompileOnly) += "-deprecation"
ensimeCompileOnly src/main/scala/MyFile.scala
I'm new to SBT, using version 1.0 and a custom repository, and I've set the "retrieveManaged" flag mentioned here, but it seems that SBT only downloads the directly requested JARs, but not any of the JARs upon which those JARs depend. And yes, the repository is using the customary default format described in the answers here (though SBT/Ivy doesn't seem capable of retrieving snapshots, either, but that's a separate problem, I expect). The repository does not require any kind of authentication, FYI.
Here's a slightly generified version of my built.sbt file:
name := "MyProject"
organization := "com.myorg"
version := "0.1"
scalaVersion := "2.9.0"
scalacOptions += "-deprecation"
retrieveManaged := true
resolvers += Resolver.url("myorg", url("http://host.com//content/groups/public"))
libraryDependencies += "com.myorg" % "otherproject" % "1.0"
fork in run := true
The requested "otherproject" JAR file loads fine, but SBT/Ivy seems to have no interest in opening up its POM and downloading the other JARs it needs to operate. This seems like it should be a fairly basic function (Maven does it, for example) but I have no idea how to convince SBT/Ivy to do so. (And the documentation assures us that SBT is, in fact, supposed to do this: "By default, these declarations fetch all project dependencies, transitively".)
I believe I must be doing something wrong, but have no idea -- given how simple and vanilla this basic configuration is -- what it could be.
Standard, Maven-style repositories are declared like:
resolvers += "myorg" at "http://host.com/content/groups/public"
More details are at the Library Management page you linked to and on the Resolvers page.
Typically, one only uses Resolver.url when specifying non-standard layouts.