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.
Related
I'm having trouble getting IntelliJ to recognize Ammonite imports in my Scala script. This is a new feature, reported here, where there are also instructions. I followed the instructions and I started a new sbt project in IntelliJ to try it out, but it's not working.
I see the Ammonite dependencies in the project's "External Libraries", which I specified in the build.sbt:
libraryDependencies += "com.lihaoyi" %% "ammonite-ops" % "1.0.3"
libraryDependencies += "com.lihaoyi" % "ammonite" % "1.0.3" cross CrossVersion.full
The (quite simple) project seems to successfully build. I also specified that Scala worksheet files should be treated as "Always Ammonite".
All this, yet the IDE shows the script like:
What more do I need to do to get this to work?
Versions:
Java 1.8.0
Scala 2.12.4
sbt 1.0.3
IntelliJ CE 2017.3.2
IntelliJ scala plugin 2017.3.11
I had similar issues with IntelliJ, so let me share how I made it work.
My versions:
IntelliJ Ultimate 2017.3.2 (so basically the same version as yours)
IntelliJ Scala plugin 2017.3.11
Kubuntu, so keyboard shortcuts below may have to be adjusted
Now, I started from the same code as you have, with updated version of dependency 0.6.7.
Already now pressing the green arrow to next to 1st line runs Ammonite. The dependencies are downloaded and link is displayed. That is mandatory step for IntelliJ to recognize that new jar is available.
Also at this stage Intellij shows me a small popup with information that I can import the jar. I did not use it.
To make IntelliJ recognize the imports, I press Alt+Enter Show Intention Actions on the broken com.lihaoyi::scalatags:0.6.7 dependency and use Create library from jar...
This makes Intellij recognize the library, imports and it can start giving you hints.
The library is added to the Project's dependencies (Ctrl+Alt+Shift+s). You can see also dependencies coming from other files below.
I had similar issues with IntelliJ and seem to be figthing bugs in IntelliJ.
My versions:
IntelliJ Ultimate 2018.2.4
IntelliJ Scala plugin 2018.2.11
OS: Windows
Scala: 2.12.6 (at the moment Ammonite current release 1.2.1 is not released for Scala 2.12.7, see #879 and below)
Without IntelliJ Project
If I just open the .sc file without open project then I get prompted with
Project JDK is not defined
No Scala SDK in module
the notification: 'Add all Ammonite standard dependencies to the project?'
The notification quickly dissapears. If I click 'Add' button before fixing the JDK, the imports does not work, and the add button is gone. fix the jdk and scala, and then find the 'Add all Ammonite...' in the eventlog and click 'add' there, then it works.
However all changes in settings are lost next time I reopen IntelliJ.
With IntelliJ Project
Create new project Scala sbt project, default directory based project.
I place my sc-files in there somewhere
Now IntelliJ remembers settings for sc-files. I can even open sc files directly from explorer/total commander in IntelliJ after configuring 'open with...' to intellij, though I prefer.
Do NOT allow IntelliJ to auto-import sbt project settings via notification, it seems to ruin the library imports, and I need to recreate project to recover.
Scala Version issues
The library auto-import 'add' button will only work for Scala versions for which Ammonite is released. See Maven Central Ammonite releases. At the time of writing Ammonite 1.2.1 is not released for scala-2.12.7, though the current unstable version of ammonite is. See Ammonite bug-report #879. The add button just fails silently, which sucks, esp. for a newbie like me.
The auto-generated sbt build file looks like this
name := "Ammonite"
version := "0.1"
scalaVersion := "2.12.6"
This is how it looks in project settings after libraries have successfully loaded:
and here are the dependencies that make it compile. Note that the 'SBT : ' dependencies are those auto-generated via SBT-file (it seems), and the others are libraries added by scala plugin ammonite notifications feature
The above library list is empty when IntelliJ fails to load the ammonite libraries.
IntelliJ with SBT (because IntelliJ loses ammonite imports, and for $ivy)
IntelliJ seems to frequently for lose its ammonite imports. If I have SBT setup to give the imports, then it does not matter so much. Also IntelliJ $ivy support for ammonite only works when files are already cached locally in ivy-cache, and running Ammonite script on my windows caches files in different location, which means IntelliJ $ivy imports effectively does not work. Hence I use SBT to setup the sum of the imports I use in my scripts.
My build.sbt
scalaVersion := "2.12.7"
// https://mvnrepository.com/artifact/com.lihaoyi/ammonite
libraryDependencies += "com.lihaoyi" % ("ammonite_" + scalaVersion) % "1.2.1-16-48ce533"
// Extra example dependency
libraryDependencies += "org.jsoup" % "jsoup" % "1.11.3"
I think IntelliJ IDEA won't find a dependency in a local cache if you're working mostly with Scala 2.13 and SBT 1.3+ with the Coursier library management. We need to help IntelliJ IDEA by downloading dependencies to the Ivy cache.
I solved this issue by:
Creating the ivy.xml somewhere with required dependencies, e.g:
<ivy-module version="1.0">
<info organisation="test" module="download-deps"/>
<dependencies>
<dependency org="com.softwaremill.sttp.client" name="core_2.12" rev="2.1.1"/>
<dependency org="com.softwaremill.sttp.client" name="okhttp-backend_2.12" rev="2.1.1"/>
<dependency org="com.github.tototoshi" name="scala-csv_2.12" rev="1.3.6"/>
</dependencies>
</ivy-module>
Note, I specified Scala 2.12 here.
Running ivy -refresh from the directory with the created ivy.xml.
Then we need is to "Create library from jar..." from the red import's context actions in IntelliJ IDEA.
That's all!
you need to associate .sc files with ammonite.
in you settings, it should look like this
(solution taken from here)
I would also recommend reading the following blog post (scroll down to Ammonite scripts support) to make sure you have all needed requirements
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!
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.
For our Scala development we currently use ivy + ant, but we are also trying to use sbt for our development workflow. This would be for the continuous incremental compilation when not using an IDE.
sbt uses ivy, so in theory this should work. But when using an ivy external file the tests won't compile.
To reproduce this you can even use the generated ivy.xml file from any sbt project.
Here are the steps to reproduce the error on a sbt project with tests,
from the sbt console run deliverLocal (deliver-local in previous versions of sbt)
copy the generated ivy file into your project home and rename it to 'ivy.xml'. From my understanding using this file should be equivalent to declaring the dependencies in build.sbt.
edit the build.sbt, add externalIvyFile() on one line and then comment all dependencies declarations
in the console, run reload, then test
compile will run just fine, but test will fail at compile time. None of the dependencies will be honoured, not even the production code of the current project.
What am I missing?
In my case it worked with the following build.sbt:
externalIvyFile()
classpathConfiguration in Compile := Compile
classpathConfiguration in Test := Test
classpathConfiguration in Runtime := Runtime
You just need the extra three lines in the end. Here is a link for more info: http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management.html#ivy-file-dependency-configuration
Look for the Full Ivy Example. I hope it helps!
EDIT: Just to be complete - here is what pointed me to the above link: https://github.com/sbt/sbt/issues/849.
I'm doing some refactoring that made compiler temporally give errors in several files. I'd like to work with them one by one (starting with common dependencies) and need some tool to check if modification is correct.
sbt compile is inconvenient because it gives too many errors and spends much time for compiling things that have no good.
I'm searching for a way to compile single file with sbt or a method for extracting sbt side libraries definition to pass them to a normal scalac compiler
There was a similar topic: How to compile just some files with sbt? that turned out to be source code error discussion rather that sbt functionality disclosure.
You could add the following line to build.sbt:
sources in Compile <<= (sources in Compile).map(_ filter(_.name == "Particular.scala"))
Then fix Particular.scala, then edit build.sbt and put the name of the next source file. If you keep the sbt console open, reload will re-read the .sbt file after you modify it.
I just wanted to mention here that I came across sbt-compile-quick-plugin (https://github.com/etsy/sbt-compile-quick-plugin). It does what it says on the tin, just add addSbtPlugin("com.etsy" % "sbt-compile-quick-plugin" % "1.3.0") to your project/plugins.sbt, then you can just start up sbt and run compileQuick /path/to/your/file