cannot launch findbugs appropriately through sbt - scala

I am trying to run findbugs-sbt plugin (https://bitbucket.org/jmhofer/findbugs4sbt/wiki/Home) for my project. However I got this error when trying to run findbugs in sbt console
[error] Exception in thread "main" java.lang.NoClassDefFoundError: edu/umd/cs/findbugs/LaunchAppropriateUI
[error] Caused by: java.lang.ClassNotFoundException: edu.umd.cs.findbugs.LaunchAppropriateUI
[error] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[error] at java.security.AccessController.doPrivileged(Native Method)
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[error] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[error] Could not find the main class: edu.umd.cs.findbugs.LaunchAppropriateUI. Program will exit.
in project/Build.scala, I just include this as described in their wiki
import de.johoop.findbugs4sbt.FindBugs._
lazy val foo = Project(..., settings = ... ++ findbugsSettings)
in project/plugins.sbt, I added this
addSbtPlugin("de.johoop" % "findbugs4sbt" % "1.2.0") // because I am using sbt 0.12
I tried to add the findbugs dependency in project/plugins.sbt
libraryDependencies ++= Seq(
"com.google.code.findbugs" % "findbugs" % "2.0.1")
but still no go.

After looking at the source code of this plugin, I found out I had to specify the findbugs classpath to make the sbt action work. For those who run into the same problem, here is the solution.
findbugsClasspath := IO.listFiles(file(<your findbugs lib location>)).filter(_.getName.endsWith("jar")).toSeq.classpath
This should've been pointed out clearly in the wiki.
BTW - I believe this could also solve the similar issue by the cpd sbt plugin.

Related

SBT native packager: reference to undefined setting Universal / mappings

I'm using the sbt-native-packager to build my Docker image and publish it to my local. I have a custom directory where I have some files that I would like to be part of the resulting Docker file system. I have tried the following in my build.sbt:
Universal / mappings += (file("data/housing.tgz"), "/opt/docker/data/housing.tgz")
But this results in an error as below:
[info] welcome to sbt 1.5.7 (Private Build Java 1.8.0_312)
[info] loading settings for project housing-price-prediction-data-preparation-build from plugins.sbt ...
[info] loading project definition from /home/joesan/Projects/Private/ml-projects/housing-price-prediction-data-preparation/project
[info] loading settings for project housing-price-prediction-data-preparation from build.sbt ...
[info] resolving key references (10159 settings) ...
Reference to undefined setting:
Universal / mappings from Universal / mappings (/home/joesan/Projects/Private/ml-projects/housing-price-prediction-data-preparation/build.sbt:58)
at sbt.internal.util.Init.Uninitialized(Settings.scala:419)
at sbt.internal.util.Init.Uninitialized$(Settings.scala:406)
at sbt.Def$.Uninitialized(Def.scala:24)
at sbt.internal.util.Init.delegate(Settings.scala:313)
at sbt.internal.util.Init.delegate$(Settings.scala:275)
at sbt.Def$.delegate(Def.scala:24)
at sbt.internal.util.Init.compiled(Settings.scala:200)
at sbt.internal.util.Init.compiled$(Settings.scala:187)
at sbt.Def$.compiled(Def.scala:24)
at sbt.internal.util.Init.makeWithCompiledMap(Settings.scala:217)
at sbt.internal.util.Init.makeWithCompiledMap$(Settings.scala:212)
at sbt.Def$.makeWithCompiledMap(Def.scala:24)
at sbt.internal.Load$.$anonfun$apply$5(Load.scala:263)
at sbt.internal.Load$.timed(Load.scala:1393)
at sbt.internal.Load$.apply(Load.scala:255)
at sbt.internal.Load$.defaultLoad(Load.scala:56)
at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:959)
at sbt.BuiltinCommands$.doLoadProject(Main.scala:959)
at sbt.BuiltinCommands$.$anonfun$loadProjectImpl$2(Main.scala:912)
at sbt.Command$.$anonfun$applyEffect$4(Command.scala:150)
at sbt.Command$.$anonfun$applyEffect$2(Command.scala:145)
at sbt.Command$.process(Command.scala:189)
at sbt.MainLoop$.$anonfun$processCommand$5(MainLoop.scala:245)
at scala.Option.getOrElse(Option.scala:189)
at sbt.MainLoop$.process$1(MainLoop.scala:245)
at sbt.MainLoop$.processCommand(MainLoop.scala:278)
at sbt.MainLoop$.$anonfun$next$5(MainLoop.scala:163)
at sbt.State$StateOpsImpl$.runCmd$1(State.scala:289)
at sbt.State$StateOpsImpl$.process$extension(State.scala:325)
at sbt.MainLoop$.$anonfun$next$4(MainLoop.scala:163)
at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
at sbt.MainLoop$.next(MainLoop.scala:163)
at sbt.MainLoop$.run(MainLoop.scala:144)
at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:119)
at sbt.io.Using.apply(Using.scala:27)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:112)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:66)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:51)
at sbt.MainLoop$.runLogged(MainLoop.scala:42)
at sbt.StandardMain$.runManaged(Main.scala:218)
at sbt.xMain$.$anonfun$run$11(Main.scala:133)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
at scala.Console$.withIn(Console.scala:230)
at sbt.internal.util.Terminal$.withIn(Terminal.scala:569)
at sbt.internal.util.Terminal$.$anonfun$withStreams$1(Terminal.scala:350)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
at scala.Console$.withOut(Console.scala:167)
at sbt.internal.util.Terminal$.$anonfun$withOut$2(Terminal.scala:559)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
at scala.Console$.withErr(Console.scala:196)
at sbt.internal.util.Terminal$.withOut(Terminal.scala:559)
at sbt.internal.util.Terminal$.withStreams(Terminal.scala:350)
at sbt.xMain$.withStreams$1(Main.scala:87)
at sbt.xMain$.run(Main.scala:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sbt.internal.XMainConfiguration.run(XMainConfiguration.java:56)
at sbt.xMain.run(Main.scala:46)
at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:111)
at xsbt.boot.Launch$.withContextLoader(Launch.scala:130)
at xsbt.boot.Launch$.run(Launch.scala:111)
at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:37)
at xsbt.boot.Launch$.launch(Launch.scala:119)
at xsbt.boot.Launch$.apply(Launch.scala:20)
at xsbt.boot.Boot$.runImpl(Boot.scala:56)
at xsbt.boot.Boot$.main(Boot.scala:18)
at xsbt.boot.Boot.main(Boot.scala)
[error] Reference to undefined setting:
[error]
[error] Universal / mappings from Universal / mappings (/home/joesan/Projects/Private/ml-projects/housing-price-prediction-data-preparation/build.sbt:58)
[error]
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)
Isn't like this how I should be adding additional folders? What is causing this error?
My plugins.sbt has the following:
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")

Error while running Spark application in Intellij - NoClassDefFoundError com/google/common/util/concurrent/internal/InternalFutureFailureAccess

I have an Apache Spark 2.0 application written in Scala (2.11.12), built using SBT tool 1.2.8. When I'm trying to run the app in Intellij (2020.3.2 Ultimate), I get the following error -
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/util/concurrent/internal/InternalFutureFailureAccess
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
.....
Caused by: java.lang.ClassNotFoundException: com.google.common.util.concurrent.internal.InternalFutureFailureAccess
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
On googling/searching Stackoverflow, it seems this is caused by some weird Guava dependency issues. I have these added to my Dependencies.scala
dependencies += "com.google.guava" % "guava" % "30.1-jre"
dependencies += "com.google.guava" % "failureaccess" % "1.0"
That didn't solve the issue. Also tried adding "com.google.guava" % "listenablefuture" % "1.0" to the dependencies, but that didn't help either. Tried doing File -> Invalidate Caches/Restart in Intellij but I still get the issue.
Could someone please help?
In my case, adding com.google.guava:failureaccess to external libraries to my project (File -> Project Structure -> Libraries) helped.

NoClassDefFoundError when running a Scala/Swing program with sbt

I am trying to compile an old school project from around March, 2015. I haven’t touched it since then. The project is written in Scala with the Swing library, and the build tool is sbt.
Apparently my build.sbt file needs updating. After digging the Internet, I found that this configuration should work.
lazy val root = (project in file (".")).
settings (
name := "MyProgram",
/* FORMERLY: */
//libraryDependencies += "org.scala-lang" % "scala-swing" % "2.10+",
//ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
/* NOW: */
scalaVersion := "2.13.0",
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "2.1.1"
)
The trick would be to use compatible versions of Scala and Swing. I tried the following pairs, which I expected to work together (either because I saw them on the webpage of package Swing, or because it worked for other people on SO):
(Scala 2.13.0, Swing 2.1.1)
(Scala 2.12.6, Swing 2.1.1)
(Scala 2.12.1, Swing 2.0.0-M)
(Scala 2.11.1, Swing 1.0.2)
I also tried switching from Java 12 (jdk-openjdk 12.0.2.u10-1) to Java 8 (jdk8-openjdk 8.u222-2).
However, all combinations give the same error. Compiling (sbt compile) works fine, but running the application (sbt run) results in a bunch of NoClassDefFoundError / ClassNotFoundException errors:
$ sbt run
[info] Loading project definition from /home/me/MyProject/project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to MyProject (in build file:/home/me/MyProject/)
[info] Compiling 22 Scala sources to /home/me/MyProject/target/scala-2.12/classes ...
[warn] there were four deprecation warnings (since 2.12.0); re-run with -deprecation for details
[warn] one warning found
[info] running Main.Main
[error] java.lang.NoClassDefFoundError: scala/swing/event/WindowOpened
[error] at scala.swing.Window$$anon$1.windowOpened(Window.scala:80)
...
[error] Caused by: java.lang.ClassNotFoundException: scala.swing.event.WindowOpened
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
...
[error] java.lang.NoClassDefFoundError: scala/swing/event/WindowActivated
[error] at scala.swing.Window$$anon$1.windowActivated(Window.scala:74)
...
[error] Caused by: java.lang.ClassNotFoundException: scala.swing.event.WindowActivated
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
...
The application’s main window shows up but is pretty unusable, with every GUI element generating more errors when activated; even trying to close the window via the window manager fails.
What is missing to run this program?

scala project does not work in intellij

I am getting the following error log when setting up a scala project in intellij:
Error:Error while importing SBT project:<br/>...<br/><pre>[error] at
sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:107)
[error] at sbt.io.Using.apply(Using.scala:22)
[error] at sbt.MainLoop$.runWithNewLog(MainLoop.scala:101)
[error] at sbt.MainLoop$.runAndClearLast(MainLoop.scala:57)
[error] at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:42)
[error] at sbt.MainLoop$.runLogged(MainLoop.scala:34)
[error] at sbt.StandardMain$.runManaged(Main.scala:113)
[error] at sbt.xMain.run(Main.scala:76)
[error] at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
[error] at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
[error] at xsbt.boot.Launch$.run(Launch.scala:109)
[error] at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
[error] at xsbt.boot.Launch$.launch(Launch.scala:117)
[error] at xsbt.boot.Launch$.apply(Launch.scala:18)
[error] at xsbt.boot.Boot$.runImpl(Boot.scala:41)
[error] at xsbt.boot.Boot$.main(Boot.scala:17)
[error] at xsbt.boot.Boot.main(Boot.scala)
[error] java.lang.ClassNotFoundException: org.jetbrains.sbt.CreateTasks$
[error] Use 'last' for the full log.
[info] shutting down server</pre><br/>See complete log in file:/home/xxxx/.IdeaIC2017.2/system/log/sbt.last.log
My build.sbt looks as follows:
name := "someProjectName"
version := "0.1"
scalaVersion := "2.12.4"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
Please also note that my "old" projects still work, i.e. this issue occurcs only when doing a new project. Further, I noticed that when I click on SBT projects on the very right, it opens an empty window "SBT projects", for my other projects that window is non-empty.
Any idea what I am doing wrong here?
Many thanks
c
In case you don't want the hassle of upgrading Intellij, you can downgrade the sbt version in sbt.properties file from 1.1.0 (the project default) to, for instance, 1.0.3.
I have been experiencing this problem myself, and solved it by upgrading to intellij version: 2017.3.2 build #IU-173.4127.27.
I think this may have to do with sbt 1.X series no longer being available on the typesafe bintray repository, as I was also having a problem performing some Docker builds.
I had the same problem, so I could not create any Scala class in my project. Found a workaround, by creating a scala module in my project:
Select your project folder, go to File menu, File->New->Module.
In module select Scala and setup your Scala SDK there.
Then you can create scala classes in this module.
downgrade the sbt version in sbt.properties and remove target folder from project and project/project

Scala run fails after adding dependency to build.sbt

I have a scala project that compiles and can be executed without errors.
I added diameter dependency in my module's build.sbt file:
libraryDependencies ++= Seq(
// some other dependencies here
// then diameter dependencies
"org.mobicents.diameter" % "jdiameter-api" % "1.7.0.106",
"org.mobicents.diameter" % "jdiameter-impl" % "1.7.0.106"
)
The project still compiles but can't run:
[app] $ compile
[success] Total time: 1 s, completed Sep 28, 2016 2:54:36 PM
[app] $ run
SLF4J: Class path contains multiple SLF4J bindings.
--- (Running the application, auto-reloading is enabled) ---
log4j:WARN No appenders could be found for logger (akka.event.slf4j.Slf4jLogger).
log4j:WARN Please initialize the log4j system properly.
java.lang.AbstractMethodError: org.slf4j.impl.Log4jLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.slf4j.bridge.SLF4JBridgeHandler.callLocationAwareLogger(SLF4JBridgeHandler.java:221)
at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:297)
at java.util.logging.Logger.log(Logger.java:738)
at java.util.logging.Logger.doLog(Logger.java:765)
at java.util.logging.Logger.logp(Logger.java:930)
at org.jboss.netty.logging.JdkLogger.debug(JdkLogger.java:36)
at org.jboss.netty.channel.socket.nio.SelectorUtil.<clinit>(SelectorUtil.java:57)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.getMaxThreads(NioServerSocketChannelFactory.java:248)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.<init>(NioServerSocketChannelFactory.java:115)
at play.core.server.NettyServer.play$core$server$NettyServer$$newBootstrap(NettyServer.scala:46)
at play.core.server.NettyServer$$anonfun$1.apply(NettyServer.scala:130)
at play.core.server.NettyServer$$anonfun$1.apply(NettyServer.scala:129)
at scala.Option.map(Option.scala:146)
at play.core.server.NettyServer.<init>(NettyServer.scala:129)
at play.core.server.NettyServerProvider.createServer(NettyServer.scala:200)
at play.core.server.NettyServerProvider.createServer(NettyServer.scala:199)
at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:208)
at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:61)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:60)
at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:50)
at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at play.runsupport.Reloader$.startDevMode(Reloader.scala:223)
at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.devModeServer$lzycompute$1(PlayRun.scala:74)
at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.play$sbt$run$PlayRun$$anonfun$$anonfun$$anonfun$$devModeServer$1(PlayRun.scala:74)
at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:100)
at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:53)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[trace] Stack trace suppressed: run last app/compile:run for the full output.
[error] (app/compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 2 s, completed Sep 28, 2016 2:54:42 PM
I don't understand how adding those two dependencies could break the application. I can see the downloaded jars in the .ivy2 cache so the new dependencies were resolved.
How can I fix this?
The full output says:
java.lang.reflect.InvocationTargetException
Many thanks for your help
Update
If I add this dependency only
"org.mobicents.diameter" % "jdiameter-api" % "1.7.0.106"
it works :)
but I need both :(
It looks like both dependencies add their own logger implementations, and they clash at runtime.
Try excluding it from one of the two, for example:
libraryDependencies ++= Seq(
"org.mobicents.diameter" % "jdiameter-api" % "1.7.0.106",
"org.mobicents.diameter" % "jdiameter-impl" % "1.7.0.106" exclude("org.slf4j", "slf4j-jdk14")
)