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
Related
I have a compiler plugin I've been adding to projects like this in my build.sbt:
addCompilerPlugin("co.blocke" %% "dotty-reflection" % "0.2.0")
In this case, I don't want the compiler plugin active during main compile, but I DO want it active during test compile. How can I specify this?
I am using some sbt plugins on a project and I would like to know which are their versions from sbt console.
I can type plugins which list the plugins but do not present their versions.
I want to do it from the sbt console, I do not want to inspect some plugins.sbt file or similar somewhere.
When you use plugins command, you see references to the plugins as they are defined in the Scala code. A single artifact can contain many plugins. Those artifacts with plugins have versions and here's how you can see them.
First load the metaproject: reload plugins
Then check dependencies: libraryDependencies
Go back to your project: reload return
You can define an alias for this in your ~/.sbt/<version>/global.sbt:
addCommandAlias("pluginsVersions", "; reload plugins ; libraryDependencies ; reload return")
It's not perfect, the output is noisy and not formatted nicely, but it's something you can get out of the box.
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.
How can I make an sbt plugin whose build definition has a dependency on code written in the plugin itself?
Because sbt is recursive, this is simple. Create or edit project/build.sbt, and add
unmanagedSourceDirectories in Compile += new File("src/main/scala")
the old answer no longer works.
Need a small tweak, add getAbsoluteFile at the end:
unmanagedSourceDirectories in Compile += file("src/main/scala").getAbsoluteFile
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.