SBT dependency-tree - scala

I am trying to see the entire SBT tree, but when I run sbt dependency-tree, I do not receive any results (after a minute or so of processing).
How can this be resolved?
Thanks
Nir

You can use this plugin to show a nice dependency tree/graph of your build dependencies. In your plugins.sbt file, add the following line:
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
Then after that, do sbt clean compile for the plugin to take effect. Then in your terminal, execute sbt dependencyTree or any other command specified in this link.
Hope that helps!

Related

Building jars with sbt

I'm following this tutorial to create a scala jar to upload to streamsets to use in a spark evaluator.
I'm using Intellij 2017.3.4.
If I use Intellij to build the artifact into the out folder, it's over 100mb in size.
If i use the 'sbt clean package' option from the command line, the jar is 3mb.
They both work fine.
Could anyone tell me why there's such a difference, and how I'd setup my Intellij so I create the smaller version?
Thanks
Matt
Without further knowledge of your build.sbt and your IntelliJ settings I can only guess that your build.sbt contains a line like this:
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.3.0" % Provided
Notice the Provided. It means that spark is not bundled in the jar that sbt prepares, but is expected to already be present at the server in which you run your program (on your class path).
IntelliJ uses all the jars (including those marked provided) so that you can debug/run your program via IntelliJ. Since you did not add your build settings in IntelliJ this is the best I can do for now.
If you use sbt assembly to package your artifact, and you want to do this with a run configuration in IntelliJ you can go to Run/Debug Configurations, click the + button, select sbt task and fill in assembly as the task.
Read more about packaging your spark app here.
I hope that helps :)

Sbt Project dependencies

I am quite new to Scala and sbt. What is the command to be used in the command line to refresh the dependencies as per the updated build.sbt ?
I already tried building my project in Intellij but it doesn't help. On a side note, what is the sbt alternative command for mvn build ?
To say to sbt to reload your changes, use reload command. You can read more about sbt commands for SBT#0.13, for SBR#1.x

SBT - Dependency missing

I did few changes in build.sbt files of working project. After changes I did sbt clean update it working fine. But While running sbt clean compile it showing compilation errors regarding squants package.
My build.sbt contains
"com.squants" % "squants_2.10" % "0.2.3" % Compile,
And I took the dependency graph tree "dependencyBrowseGraph". It not showing anything regarding squants package. What can I try to resolve this?
It happen because of missing squants library in one of the modules in same project.

Running sbt with Wartremover

I'd like to check the code of my whole project with wartremover and sbt.
I've added addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.13" to plugins.sbt, but don't know what to do next.
I don't get any output from wartremover with sbt run and sbt compile.
Like said in the documentation, you will need to configure the linter:
wartremoverErrors ++= Warts.unsafe
With sbt >= 0.13.5 and the auto plugin feature, that's all. I get compilation errors with the examples as soon as I add the line above.

How to build a jar file out of github project in sbt to be used in a scala program

I am trying to use scala to access Amazon's DynamoDB and found this great package on github https://github.com/piotrga/async-dynamo
so I downloaded the code as a zip file , unzipped it and then did "sbt clean test" and getting the following error
error sbt.ResolveException: unresolved dependency: asyncdynamo#async-dynamo;1.6.0: not found
Questions : is this the correct way to generate a jar file that I can include in my Scala program or is there a better way?
thanks in advance.
EDIT:
just for the benefit of others, the SCALA SBT documentation provides lots of information regarding the build process.
Instead of generating a jar file, you can just run 'sbt publish-local' and then include the lines for the managed dependency in the other project.
Sbt/ivy will see you have the artifact that way you don't need to add the jar to the other project which is much cleaner.
Then for example if you need to update the other project you don't need to replace the jar again - just publish-local again and clean and run your other project!
You are not the only one to have problems with this it seems, see github issues page:
https://github.com/piotrga/async-dynamo/issues
The command 'sbt clean test' will run the tests sbt detects. If you want a .jar file you could use 'sbt clean package', which produces a .jar in the target/ folder.
I cloned the repo and was able to run sbt package after changing release.sbt a bit. I had to change the 'publishTo'-variable as it seemed to depend on the repository creators local environment variable, so I just commented it away.
I did not get the dependency problem, so I suppose it is correctly declared. The tests it tries to run do fail though, but sbt package compiles produces the .jar just fine.
EDIT: As Matthias Schlaipfer pointed out in the comments, the more elegant way(and much easier) would just be to add this as an depency in your build.sbt. From the readme, this is what you need to add:
resolvers += "piotrga" at
"https://github.com/piotrga/piotrga.github.com/tree/master/maven-repo"
libraryDependencies += "asyncdynamo" % "async-dynamo" % "1.6"