Executing sbt run in current project with ensime emacs - emacs

I have a Scala project called scala-playground and I generated the configuration for Ensime with sbt ensimeConfig and sbt ensimeConfigProject.
When running M-x ensime from a buffer of the project, I can see in the Emacs statusbar that Ensime is connected: it displays Scala[scala-playground].
When running the project with C-c C-b r, a new sbt instance is started in the home directory, a directory in $HOME/project is created and instead of the project directory and fails:
[info] Loading project definition from /home/user/project
[info] Set current project to user (in build file:/home/user/)
[info] sbt server started at 127.0.0.1:4766
sbt:user>
sbt:user> run
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:27)
[error] at sbt.Defaults$.$anonfun$runTask$4(Defaults.scala:1199)
[error] at scala.Option.getOrElse(Option.scala:121)
[error] at sbt.Defaults$.$anonfun$runTask$3(Defaults.scala:1199)
[error] at sbt.Defaults$.$anonfun$runTask$3$adapted(Defaults.scala:1198)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42)
[error] at sbt.std.Transform$$anon$4.work(System.scala:64)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:257)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
[error] at sbt.Execute.work(Execute.scala:266)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:257)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:32)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] at java.lang.Thread.run(Thread.java:748)
[error] (compile:run) No main class detected.
[error] Total time: 0 s, completed Aug 28, 2017 9:10:03 PM
What is going on?

Short story
Remove ~/project folder and then start emacs.
Long story
If you ever run sbt in your $HOME directory it created basic project structure there, mainly project and target directory. And then if you open any *.scala file emacs (sbt-mode) will go up your path to find root project directory. And it finds one in your $HOME. You can see it in doc's:
Starting from the current default-directory, find a parent
directory that is an sbt root. An sbt root directory is
identified by the following rules:
- a directory containing a 'project/build.properties' in it.
- a directory that contains a file matching one of the patterns
'*.sbt' or 'project/*.scala' file in it.
One problem with current implementation is fact that this process will be done only once per buffer. If sbt:buffer-project-root variable is set once it will be not updated.
You can force a new value either by restarting emacs, or by evaluating (setq-local sbt:buffer-project-root nil) per each opened buffer, and then starting sbt form emacs in the usual way.
If you remove ~/project and run ensime-sbt from any buffer with sbt:buffer-project-root with wrong value, it will start sbt in home, which creates ~/project again. So again, the easiest way is to kill emacs, remove the directory, and then start emacs again.

Related

sbt / native-packager, new jdeps error: java.lang.module.FindException: Module java.activation not found, required by java.xml.bind

I have not changed my setup as far as I can see. As of today, trying to run sbt native packager with jlink gives this error:
[info] Running: jdeps --multi-release 11 -R ...
[error] Exception in thread "main" java.lang.module.FindException: Module java.activation not found, required by java.xml.bind
[error] at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
[error] at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
[error] at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
[error] at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main.run(Main.java:64)
[error] at jdk.jdeps/com.sun.tools.jdeps.Main$JDepsToolProvider.run(Main.java:73)
[error] at java.base/java.util.spi.ToolProvider.run(ToolProvider.java:137)
[error] at ru.eldis.toollauncher.ToolLauncher.runTool(ToolLauncher.java:68)
[error] at ru.eldis.toollauncher.ToolLauncher.lambda$main$1(ToolLauncher.java:33)
[error] at ru.eldis.toollauncher.ToolLauncher.main(ToolLauncher.java:48)
How do I fix this? I tried adding javax.activation to libraryDependencies, that doesn't seem to have any effect or anything to do with this problem.
Edit: The root problem of seems to be my dependency on Pi4j 1.4, which depends on javax.xml.bind:jaxb-api which in turn depends on javax.activation:javax.activation-api. Now I don't understand much of this Java module stuff, but javax.activation-api does exist on Maven, so why does jdeps complain? If I exclude javax.xml.bind, it works, but now I'm worried I'm actually missing stuff on the class path.
javax.activation has been removed since java 11.
To fix it you can:
Download the javax.activation jar and run the command by adding this jar on module path:
jdeps --multi-release 11 -R --module-path path\to\javax.activation.jar ...
Running this command with java 8 jdeps

PlayFramework - Creating Scala seed template with sbt

I am attempting to create the PlayFramework Scala seed project.
So far I've used sbt new playframework/play-scala-seed.g8 command and it has created the necessary files within my root directory movie-app.
From this point, PlayFramework says to run sbt run, so I tried that, but I get the following error:
[info] Updated file *omitting personal directories*/Movie-App/project/build.properties: set sbt.version to 1.4.7
[info] welcome to sbt 1.4.7 (Ubuntu Java 11.0.10)
[info] loading project definition from *omitting personal directories*/Movie-App/project
[info] set current project to movie-app (in build file:*omitting personal directories*/Movie-App/)
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed Jul 2, 2021, 11:27:33 PM
I haven't found anything helpful online yet.
Do I need to set the current project to "movie-app" like the error says? If so what do I need to write in the build.properties file?
If not, can anyone please explain the issue?
Thanks
$> sbt new playframework/play-scala-seed.g8
This template generates a Play Scala project.
Give it a name when asked. Skip rest by pressing enter.
name [play-scala-seed]: movie-app
$> cd movie-app
$> sbt run

When documentation's Usage merely says `> fooBar` what does that mean?

Yes, a beginner question! I'm looking at https://github.com/sbt/sbt-license-report and see the usage section of:
> dumpLicenseReport
This dumps a ...
Well no, that is a partial application of the greater-than operator, >. But seriously, I think this means:
One: Run sbt
$ sbt
... debug info ...
[proj-name] $
OK, we're in a sort of REPL. Now two: dumpLicenseReport:
[proj-name] $ dumpLicenseReport
[error] dumpLicenseReport
[error] ^
Ok so that wasn't a repl so much as an "sbt shell". In this shell one valid command is console which does get to a repl:
[proj-name] $ console
...
scala> dumpLicenseReport
^
error: not found: value dumpLicenseReport
OOps, I didn't define the license.sbt file they show in the instructions. Doing that then...
[proj-name] $ console
...
scala> dumpLicenseReport
...
[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.sbt:sbt-license-report;sbtVersion=1.0;scalaVersion=2.13:1.2.0
[error] Not found
[error] Not found
[error] not found: .../.ivy2/local/com.typesafe.sbt/sbt-license-report/scala_2.13/sbt_1.0/1.2.0/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-license-report_2.13_1.0/1.2.0/sbt-license-report-1.2.0.pom
[error] not found: https://repo.typesafe.com/typesafe/releases/com/typesafe/sbt/sbt-license-report_2.13_1.0/1.2.0/sbt-license-report-1.2.0.pom
[error] Total time: 1 s, completed Feb 5, 2021, 10:18:25 PM
Now I'm guessing I just need to enter the right upstream location somewhere but I've not used sbt before. Would someone show me how to go from a *nix system with bash + sbt + jdk11 to running sbt-license-report?
#LuisMiguelMejíaSuárez indicated this is an SBT command intended to be ran from an SBT shell so the process is:
Enter your repository directory
Ensure you created license.sbt correctly, including having it under the project sub directory.
run sbt compile
run sbt dumpLicenseReport
Or Instead of steps 3 and 4 you can enter the shell with just sbt and execute commands of compile then dumpLicenseReport. The > prompt in the readme of the sbt-license-report repository indicates an SBT shell and not a repl (the "console") and certainly not a naked *nix shell (bash, zsh, etc).

Using Play 2.4 with a renamed `conf/routes` file

My simple Play 2.4 project does not compile when I rename the conf/routes file to something else, e.g. conf/hello.routes. The reason I'm doing this is to enable composition of APIs while allowing them to be developed in separate git repositories and sbt projects.
The idea of multiproject support is based on this project and blog post - but that's using Play 2.3.
The error I get is:
$ sbt test
...
[info] Hello should
[error] ! give {hello: true}
[error] Unable to provision, see the following errors:
[error]
[error] 1) Error in custom provider, java.lang.ClassCastException: interface play.api.routing.Router is not assignable from class hello.routes
[error] while locating play.api.test.FakeRouterProvider
[error] while locating play.api.routing.Router
[error]
[error] 1 error (InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
[error] com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
[error] play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316)
...
Got this resolved (code in the git repo now works).
The problems were likely connected to both of these:
the Controller implementation wants to be within a package controllers.hello instead of just hello
in the application.conf file one should omit the controllers namespace, i.e.
play.http.router = app.Routes
I learned this simply by comparing this code with samples that work.

Can't get path to resource

I am trying to use Scala macro annotations with this library.
I have a schema file at src/main/resources/avsc/FriendRequestAcceptedGson.avsc
I am trying to refer to it in my code as follows:
#AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")
#AvroRecord
case class FriendRequestAcceptedGson()
This is the error I get:
[error] /home/lee/Code/bigdata-friends/java/etl/src/main/scala/com/mxit/bd/friends/etl/Runner.scala:64: exception during macro expansion:
[error] java.io.FileNotFoundException: /avsc/FriendRequestAcceptedGson.avsc (No such file or directory)
[error] at java.io.FileInputStream.open(Native Method)
[error] at java.io.FileInputStream.<init>(FileInputStream.java:146)
[error] at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:504)
[error] at org.apache.avro.Schema$Parser.parse(Schema.java:922)
[error] at com.julianpeeters.avro.annotations.util.SchemaParser$.getSchema(SchemaParser.scala:20)
[error] at com.julianpeeters.avro.annotations.AvroTypeProviderMacro$.impl(TypeProviderMacro.scala:23)
[error] #AvroTypeProvider("/avsc/FriendRequestAcceptedGson.avsc")
Resources are compiled into your JAR file. You must find them with a ClassLoader, not in the file system. The java.io.FIle class only knows how to look in the file system. Now, if you're trying to open the source file (which may not be present when the JAR is deployed), it will depend on where your current working directory is relative to the file. Probably it is at the root so the path you need to use is the full relative one: src/main/resources/avsc/FriendRequestAcceptedGson.avsc