Creating empty eclipse project using sbt - scala

When I run eclipse in sbt with build.sbt having,
name := "test"
version := "0.1"
scalaVersion := "2.10.5"
It had build.sbt, project and target but, in tutorial I was following it was mentioned src/main/scala, src/main/java, ..test will be available where I can code in eclipse by importing.
What am I doing wrong?
I have added addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0") in ~\.sbt\0.13
Appreciate some help

Related

Using IntelliJ, how to add dependency in an sbt project

I'm new to sbt and I wanted to learn it with a small Scala project in IntelliJ.
I started with the official sbt Getting Started guide, to learn the sbt basics on the console (https://www.scala-sbt.org/1.x/docs/sbt-by-example.html). Following the guide, everything compiles fine.
Then I created an sbt project in IntelliJ, trying to do the same thing there. When I add the org.scalatest depenpency to the build.sbt file the project can no longer compile. The error message is:
module not found: org.scalatest#scalatest_2.13;3.0.5
When I created the fresh sbt project in IntelliJ, first the build.sbt looked something like this:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
Then I added the dependency:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
After reloading the build file and getting the error when compiling, I tried to change the biuld.sbt according to the code which already worked in the sbt Getting Started guide:
ThisBuild / scalaVersion := "2.13.0"
ThisBuild / organization := "me"
ThisBuild / version := "1.0"
lazy val sbtTest = (project in file("."))
.settings(
name := "sbtTest",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
)
This has again the same error after reloading and compiling.
My sbt version is 1.2.8.
Is something wrong with my build.sbt? Or is the sbt version too new for IntelliJ? Is IntelliJ probably not the recommended IDE to create Sala sbt projects?
Structure of both your build.sbt is ok. The thing seems to be in versions.
Scalatest 3.0.5 is currently unavailable for Scala 2.13.0. It's available for Scala 2.13.0-M2.
It's Scalatest 3.0.8 that is available for Scala 2.13.0.
https://mvnrepository.com/artifact/org.scalatest/scalatest
After you fix versions in build.sbt re-import IntelliJ project in pop-up window
or in sbt tool window
or in sbt shell

Not able to import Specs2 in eclipse (scala-ide) project

Kindly consider if there's something very stupid I am missing, I am very new to this.
Creating this example on Eclipse (Scala-ide). When I create the CorrelationJobTest.scala class, there's a problem in importing classes from specs2 package.
import org.specs2.runner.JUnitRunner
The error I am getting is pretty obvious,
object specs2 is not a member of package org
Even after creating a build.sbt file, adding the dependencies, and doing a sbt clean, the error is still showing.
Below is my build.sbt
name := "SparkCorrelation"
organization := "com.xyz"
version := "0.1"
/* scala versions and options */
scalaVersion := "2.10.4"
// These options will be used for *all* versions.
javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")
scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation")
/* dependencies */
libraryDependencies ++= Seq("org.specs2" %% "specs2-core" % "3.7" % "test")
scalacOptions in Test ++= Seq("-Yrangepos")
EDIT:
I faced this problem with apache.spark packages too. Then I included the jar spark-assembly-1.6.0-hadoop-2.6.0.jar and it got solved. Isn't there a library for specs2 that I can import in Eclipse?
Got it working. Here's what I did:
Deleted the project from eclipse
Did sbt eclipse
Imported the project into eclipse again.
Added dependencies in build.sbt
Did sbt clean
The problem was that the project was directly created in eclipse and was not able to link to sbt build file.
You need to add the junit module to your dependencies
libraryDependencies ++= Seq(
"org.specs2" %% "specs2-core" % "3.7" % "test",
"org.specs2" %% "specs2-junit" % "3.7" % "test")

Can't install Scaladoc with SBT and Intellij

I am new to scala and am currently trying to setup IntelliJ IDEA 13.1 with the Scala plugin. It has support for SBT. I have simply followed the basic tutorial for creating a new project for SBT here: http://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT
Currently my build.sbt file is:
name := "scalasandpit"
version := "1.0"
scalaVersion := "2.10"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
autoAPIMappings := true
This pulls down various jar binaries, but no sources and no javadoc. I wondered if there is a way to have both sources and javadoc work with IntelliJ and SBT. I think I'm missing something.
There seem to be two issues: getting sbt to pull down sources and docs, and then getting Idea to show them to you. To solve the former problem see the sbt documentation -- about half way down there's a section called "Download Sources" which tells you what to add to your build.sbt:
libraryDependencies +=
"org.scalatest" % "scalatest_2.10" % "2.1.0" % "test" withSources() withJavadoc()

installing sbt-assembly with sbt 0.11.2

I am trying to install sbt-assembly by following the instructions in order to make a stand-alone jar that can run on a computer without scala installed.
So far these are the steps I've taken.
I created a plugins.sbt file:
$ cat sbt/project/plugins.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
And I added the following to the beginning of my build.sbt file:
$ head -n3 sbt/build.sbt
import AssemblyKeys._ // put this at the top of the file
seq(assemblySettings: _*)
But when I run sbt, I get the following error:
sbt/build.sbt:1: error: not found: value AssemblyKeys
import AssemblyKeys._
Make sure you are running sbt version at least 0.11 by typing
$ sbt sbt-version
at the bash prompt.
Make sure you have the plugins file set up as follows:
$ cat sbt/project/plugins.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
Make your build file (build.sbt) look like this:
import AssemblyKeys._
seq(assemblySettings: _*)
name := "my_project"
version := "1.0"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "1.6.1" % "test",
"commons-lang" % "commons-lang" % "2.6"
)
traceLevel in run := 0
fork in run := true
scalacOptions ++= Seq("-optimize")
// The following is the class that will run when the jar is compiled!
mainClass in assembly := Some("MyMain")
Make sure you don't have a project/plugins folder lying around. This may prevent other mechanisms of specifying plugins from working.
You shouldn't import plugin settings into build.sbt (basic configuration): 1) build.sbt is not a normal Scala source file 2) plugin settings are pre-imported.
So you simply should do
seq(assemblySettings: _*)
Imports are required only when you use full/extended build configuration.

How to set up managed dependencies in an SBT 0.11 project having Build.scala

I am building a simple Scala project with SBT 0.11.
All the code files are in ~/MyProject/src/main/scala/
~/MyProject/build.sbt is the following
name := "MyProject"
version := "1.0"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.+",
"c3p0" % "c3p0" % "0.9.1.2",
"org.apache.commons" % "commons-lang3" % "3.0.1",
"commons-lang" % "commons-lang" % "2.6",
"javassist" % "javassist" % "3.12.1.GA"
)
~/MyProject/project/Build.scala is the following
import sbt._
object MyProjectBuild extends Build {
lazy val MyProject = Project("MyProject", file("."))
}
This seems to work almost fine. The project does compile and run. The project name is set correctly (if I don't use Build.scala, then the name seems to appear something like "default-????", despite it being specified in build.sbt).
But the problem is that dependencies do not seem to work - update command doesn't download anything. How to fix this? Do I need to specify my dependencies in Build.scala rather than in build.sbt in this case?
Is it possible that you've already retrieved the project dependencies, but don't realize it because they are stored in the Ivy cache? You can view the managed classpath from the SBT console with the command
show managed-classpath
Recent versions of SBT do not store the managed dependencies in the project directory, unless the project is configured to do so. If you want, you can add the following to your build.sbt file:
retrieveManaged := true
This will create a ~/MyProject/lib_managed/ directory and contents.