How to invoke plugin from command line (sbt beginner)? - scala

Following https://scalameta.org/scalafmt/docs/installation.html I'm trying to reformat my Scala code via command line.
How to execute the scalafmt command ?
Loading sbt from the project can I invoke scalafmt ?
Using below returns error :
sbt:skeleton> scalafmt
[error] Not a valid command: scalafmt (similar: last)
[error] Not a valid project ID: scalafmt
[error] Expected ':'
[error] Not a valid key: scalafmt (similar: scalaHome, scalaArtifacts, scalaInstance)
[error] scalafmt
[error] ^
sbt:skeleton> my-project/scalafmt
[error] Expected ':'
[error] Not a valid key: scalafmt (similar: scalaHome, scalaArtifacts, scalaInstance)
[error] my-project/scalafmt
[error] ^
sbt:skeleton>

First I would suggest checking your project/plugins.sbt if it includes
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % scalaMetaVersion)
looks like it can't find scalafmt command.
Second run sbt plugins to check if it's enabled - you should have something like this: org.scalafmt.sbt.ScalafmtPlugin: enabled in skeleton

Related

IntelliJ can't import sbt project

Error while importing sbt project:
d; set _root_.org.jetbrains.sbt.StructureKeys.sbtStructureOptions in Global := "download resolveClassifiers" ;*/*:dumpStructureTo /private/var/folders/5v/g3zxt_7d64g3sd_56bzpqbvh0000gn/T/sbt-structure.xml; session clear-all
[error] Expected ID character
[error] Not a valid command: d
[error] Expected 'debug'
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: d
[error] d; set _root_.org.jetbrains.sbt.StructureKeys.sbtStructureOptions in Global := "download resolveClassifiers" ;*/*:dumpStructureTo /private/var/folders/5v/g3zxt_7d64g3sd_56bzpqbvh0000gn/T/sbt-structure.xml; session clear-all
[error] ^
The error appeared after I upgraded the sbt version to sbt.version=0.13.16 in ./project/build.properties. Using sbt from the terminal works just fine.
Update: A workaround I found is to disable importing the project via the sbt shell.
Try deleting the target folder and running the commands again

What is wrong with my project hierarchy?

I have created a project by importing existing sources in Intellij IDEA.
When I run from my comand line,sbt and then console I got this
[info] Compiling 7 Scala sources to
/home/milenko/example/project/target/scala-2.10/classes...
[error] /home/milenko/example/project/CommonBuild.scala:20: not found: type ModuleID
[error] dependencies: Seq[ModuleID] = Seq(),
[error] ^
[error] /home/milenko/example/project/CommonBuild.scala:26: not found: type Build
[error] trait CommonBuild extends Build {
[error] ^
[error] /home/milenko/example/project/CommonBuild.scala:28: not found: value SettingKey
[error] val course = SettingKey[String]("course")
[error] ^
[error] /home/milenko/example/project/CommonBuild.scala:30: not found: value SettingKey
[error] val assignment = SettingKey[String]("assignment")
[error] ^
[error] /home/milenko/example/project/CommonBuild.scala:32: not found: value SettingKey
[error] val assignmentsMap = SettingKey[Map[String, Assignment]]("assignmentsMap")
My example folder
milenko#milenko-desktop:~/example$ ls
assignment.sbt build.sbt project src target
Then I have changed directory to project,and run sbt and console in project.
My IDEA import is here
It seems that CommonBuild.scala is not positioned at the wright place.How to change this?
You should run sbt command from the root of your build, not in the project directory. project directory is used to build the build definition of your project, because sbt is recursive.
In other words, in your case you need to run sbt in ~/example directory.

How to install sbt-sh plugin

https://github.com/steppenwells/sbt-sh
I'm using sbt 0.13.9 and try to install sbt-sh with given instructions. However sbt does not recognize sh command:
> sh ls
[error] Expected ID character
[error] Not a valid command: sh
[error] Expected 'show'
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: sh
[error] sh ls
[error] ^
>
Instructions are for sbt 0.10, maybe things have changed since those days and this guide is out of date?
The instructions are a bit outdated. Instead of ~/.sbt/plugins/project, you should put the MyPlugins object in ~/.sbt/0.13/plugins/project/MyPlugins.scala.
However, sbt-sh doesn't seem to work, even with that correction:
[error] $HOME/.sbt/0.13/staging/1375c2d4ab8153e18523/sbt-sh/src/main/scala/org/sbtsh/SbtShPlugin.scala:4: object CommandSupport is not a member of package sbt
[error] import sbt.CommandSupport._
[error] ^
[error] one error found
[error] ({git://github.com/steppenwells/sbt-sh.git}sbt-sh/compile:compileIncremental) Compilation failed
Can you try xsbt-sh instead?
Create a file ~/.sbt/0.13/plugins/xsbt-sh.sbt with this content:
resolvers += "Element Releases" at "http://repo.element.hr/nexus/content/repositories/releases/"
addSbtPlugin("hr.element.xsbt" % "xsbt-sh" % "0.0.2")
The Github README refers to 0.1.0 but that doesn't seem to have been yet released to the repository.

How can I enable remote debugging for SBT in windows?

I would like to accomplish running the equivalent of this
sbt -jvm-debug 5005
However I don't seem to be able to pass in args in Windows. This is what I am seeing
>sbt -jvm-debug 5005
[info] Loading project definition from [myProject]
[info] Set current project to [myProject] (in build file myProject)
[error] Expected letter
[error] Expected symbol
[error] Expected '!'
[error] Expected '+'
[error] Expected '++'
[error] Expected ';'
[error] Expected end of input.
[error] Expected 'show'
[error] Expected '*'
[error] Expected '{'
[error] Expected project ID
[error] Expected configuration
[error] Expected key
[error] 5005
[error] ^
[error] Not a valid command: jvm-debug
[error] Not a valid project ID: jvm-debug
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: jvm-debug
[error] jvm-debug
[error] ^
I would like to be able to remote debug this application from Intellij. Any help would be great!
set SBT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
sbt run
was the only working solution on Windows 7.
Seems like the Windows version of SBT doesn't define this functionality.
On Linux it is defined in the $SBT_HOME/sbt/bin/sbt-launch-lib.bash as
addDebugger () {
addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
}
You can achieve the same result by setting the SBT_OPTS environmental variable on Windows.
Run SBT like this, to make the debugger listen on port 5005
set SBT_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" && sbt
Currently, I'd downloaded the last updated sbt, exactly sbt 1.3.3 but when I want to enable debug in the project, I had the same problem as you. Investigating, I could see that I haven't this file (sbt-launch-lib.bash) in my own root C:\Program Files (x86)\sbt\bin so when I see in another machine, I could notice that sbt, It was 1.2.8 and yes it had the file that I mentioned before so I uninstalled sbt 1.3.3 and I installed sbt 1.2.8 and put in my project sbt -jvm-debug 9999 and it works.

Not a valid key: eclipsify

I'm trying out the todolist play framework application from their documentation. But when I try to create the eclipse project, using eclipsify command, I get this error
[todolist] $ eclipsify
[error] Not a valid command: eclipsify (similar: eclipse)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: eclipsify
[error] eclipsify
[error] ^
What could be wrong?
It is now eclipse or idea, not eclipsify or idealize.
Append this piece to your plugins.sbt file:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
then use eclipse not eclipsify