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?
Related
My sbt version is 1.1.5
I read readme in git,and add addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") in plugins.sbt .
When I use enablePlugins(GitVersioning), it's red, "Cannot resolve symbol GitVersioning"
New user to sbt, cannot figure out where did I missed.
Reload project and error will dissapear.
Every change to sbt build definition (e.g. build.sbt, plugins.sbt) requires sbt project rebuild.
If working directly from sbt, type reload or from console sbt reload
If working from IntelliJ, then right click on sbt project and choose Refresh sbt project (rebuild once) or Auto-import (rebuild on every change).
You have to add addSbtPlugin line to project/plugins.sbt file (create it if doesn't exist). Then add enablePlugins(GitVersioning) to your build.sbt (in the root directory of your project).
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 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 write a plugin "MyPlugin" that depends on the another plugin
("io.spray" %% "sbt-twirl" % "0.6.0").
Simply adding sbt-twirl in libraryDependencies will not work,
because plugins get published with a different path scheme
than standard libraries.
I also cannot declare sbt-twirl as a plugin dependency to MyPlugin
project, because MyPlugin does not use the sbt-twirl directly,
it is the project using MyPlugin that will indirectly use it.
MyPlugin provides a task that is meant to be run after sbt-twirl
has generated it's sources (in sourceManaged) and after compilation.
A simple but non ideal solution would be to require the project using
MyPlugin to also declare sbt-twirl as a plugin dependency, but it is not
DRY because the two plugins will be sharing some settings (directories, versions, etc),
and they will have to be repeated and compatible.
It should be the same definition as for using a plugin as a plugin, except that it goes in build.sbt or project/Build.scala instead of project/plugins.sbt:
addSbtPlugin("io.spray" % "sbt-twirl" % "0.6.0")
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