How to set up Scala X-Ray plugin? - scala

I want to use the Scala X-Ray plugin.
I compiled the plugin and dropped the jar file - sxr-0.3.1-SNAPSHOT.jar - in ~/.sbt/0.13/plugins and wrote Scalatron's plugin.sbt (as project/plugin.sbt) to configure the plugin as follows:
addCompilerPlugin("org.scala-tools.sxr" % "sxr" % "0.3.0-SNAPSHOT" cross CrossVersion.full)
scalacOptions <+= scalaSource in Compile map { "-P:sxr:base-directory:" + _.getAbsolutePath }
Then, I tried to sbt dist the project that failed at compilation:
sbt dist
But compilation was failed:
.../scalatron-master/project/plugins.sbt:10: error: not found: value CrossVersion
addCompilerPlugin("org.scala-tools.sxr" % "sxr" % "0.3.0-SNAPSHOT" cross CrossVersion.full)
^
[error] Type error in expression
Can anyone help me with the plugin's configuration?

There are two issues with the documentation on the sxr project's page and in Compiler Plugin Support.
First, the compiler plugin's in the Typesafe Releases repository so you need to add a proper resolver.
Second, the compiler plugin's changed the package that's now org.scala-sbt.sxr.
That said, the build.sbt of your project should be as follows:
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/"
addCompilerPlugin("org.scala-sbt.sxr" %% "sxr" % "0.3.0")
scalacOptions <+= scalaSource in Compile map { "-P:sxr:base-directory:" + _.getAbsolutePath }
p.s. I submitted a pull request to update README.md in the browse's github repository.

I think you're suppose to put
addCompilerPlugin("org.scala-tools.sxr" % "sxr" % "0.3.0-SNAPSHOT" cross CrossVersion.full)
scalacOptions <+= scalaSource in Compile map { "-P:sxr:base-directory:" + _.getAbsolutePath }
in your build.sbt, not project/plugins.sbt.

Related

Scala SBT elasticsearch-hadoop unresolved dependency

When adding dependency libraryDependencies += "org.elasticsearch" % "elasticsearch-hadoop" % "5.1.1" and refreshing project, I get many unresolved dependencies(cascading, org.pentaho,...).
However if I add another dependency, like libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.1.0" it works and I can use the library in my scala files.
So, is the problem coming from elasticsearch-hadoop ? I'm using SBT 0.13.13 but also tried with 0.13.8.
I took the dependency from https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch-hadoop/5.1.1 I know that for some dependencies you need to add the repository aswell (resolvers += ...), but here it doesn't seems to need a repo.
Add the following in your build.sbt file:
resolvers += "conjars.org" at "http://conjars.org/repo"
Can update your .sbt file
name:="HelloSparkApp"
version:="1.0"
scalaVersion:="2.10.4"
libraryDependencies+="org.apache.spark"%%"spark-core"%"1.5.2"
And execute the below commands from the project directory
sbt clean
sbt package
sbt eclipse

Can not resolve dependencies after upgrading to version 2.12

Because I had some dependency issues, I decided to upgrade the Scala installation on my computer to version 2.12.0-M3. I also ran sbt -v, after which many packages were downloaded.
However, when I try to refresh the following build.sbt file
name := """ScalaWeb"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.12.0-M3"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"org.sorm-framework" % "sorm" % "0.3.18"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
scalacOptions += "-Ylog-classpath"
I get the following errors:
Error:Unresolved dependencies:
com.typesafe.play#twirl-api_2.12.0-M3;1.1.1: not found
com.typesafe.play#play-server_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-netty-server_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-jdbc_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-cache_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-ws_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-test_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-specs2_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-omnidoc_2.12.0-M3;2.4.6: not found
Version 2-12.0-M3 appeared in October 2015. It seems doubtful that all these packages are still incompatible.
How can I solve this issue?
PS
I was unable to use scala version 2.11.7 because I have the dependency
"org.sorm-framework" % "sorm" % "0.3.18"
Which, because of its dependencies, produces this issues:
[error] org.scala-lang.modules:scala-xml _2.11, _2.12.0-M3
[error] org.scala-lang.modules:scala-parser-combinators _2.11, _2.12.0-M3
It seems the SORMS author is defining Scala library dependencies wrongly. As a result you have horrible transitive Scala dependencies for versions like [2.10,2.12), so it will pick whatever latest Scala version was published, including in your case 2.12.0-M3 apparently.
Looking at the POM of 0.3.18 and the POM of 0.3.19, it seems that the later version uses (still wrong!!) [2.10,2.11.999).
So I think you can solve your issue using these settings:
scalaVersion := "2.11.7"
libraryDependencies += "org.sorm-framework" % "sorm" % "0.3.19"
If not, you will have to exclude the problematic transitive dependencies from SORM.
Update: The bug report also hints that the dependency you need to exclude is actually embrace. For example, using the sbt-dependency-graph plugin, running sbt dependency-dot and inspecting the result I find:
"com.github.nikita-volkov:embrace:0.1.4" -> "org.scala-lang:scala-compiler:2.12.0-M3"
which seems to be the origin of the evil.
Instead of excluding, I am now forcing a version of Scala:
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.sorm-framework" % "sorm" % "0.3.19",
"org.scala-lang" % "scala-compiler" % scalaVersion.value force() // !!
)
This worked for me.

SBT Compiler Plugin as Transitive Dependency

I have a library that uses the macro paradise plugin (referred to as macro-provider library). In the build.sbt,
addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.0" cross CrossVersion.full)
to gain access to the macro annotations.
When adding the macro library as a libraryDependency to a separate project (referred to as macro-consumer project), the annotations are present, but the macro implementation is never called. Adding the macro paradise compiler plugin to the macro-consumer project libraryDependencies solves the problem.
Is it possible to include compiler plugins as transitive dependencies? This would free consumers of the macro library from adding the required plugin.
Update #1:
The addCompilerPlugin helper adds the dependency to the libraryDependencies and sets the dependency with a configuration = Some("plugin->default(compile)") within the macro-provider library.
Adding the paradise dependency in the libraryDependencies of the macro-provider library causes the artifact to show up in the macro-consumer project. It does not add the dependency as a compiler plugin.
Update #2:
Setting autoCompilerPlugins := true in the macro-consumer project in conjunction with Update #1 does not resolve the issue.
The only way I found to resolve this issue was by adding a sbt-plugin sub-module that includes the settings required. The plugin is very basic,
package fixme
import sbt._
import Keys._
object Plugin extends sbt.Plugin {
val paradiseVersion = "2.0.0"
val fixmeVersion = "1.4"
val fixmeSettings: Seq[Setting[_]] = Seq(
resolvers += "tysonjh releases" at "http://tysonjh.github.io/releases/",
libraryDependencies <++= (scalaVersion) { v: String ⇒
(if (v.startsWith("2.10")) List("org.scalamacros" %% "quasiquotes" % paradiseVersion % "compile")
else Nil) :+
"org.scala-lang" % "scala-reflect" % v % "compile" :+
"com.tysonjh" %% "fixme" % fixmeVersion % "compile"
},
addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full))
}
This can be used by including in your project/plugins.sbt,
resolvers += "tysonjh releases" at "http://tysonjh.github.io/releases/"
addSbtPlugin("com.tysonjh" % "sbt-fixme" % "1.4")
and the build.sbt file,
fixmeSettings
The sbt-plugin settings add the macro paradise plugin as a compiler dependency and the macro implementation as a library dependency.

How does one get sbt-idea to work in scala-2.10 project?

I had a lot of trouble getting sbt-idea to work in my Scala 2.10 project.
I tried compiling sbt-idea from its git repo, making sure that to have set
scalaVersion := "2.10.0-RC5"
in build/Build.scala, and using publish-local command to compile it in git. But I nevertheless keep getting
[error] sbt.IncompatiblePluginsException: Binary incompatibility in plugins detected.
when I then use that in my published version, say by simply adding
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT")
to the project/plugins.sbt file.
Don't think you need to build SBT for Scala 2.10. I keep my gen-idea and eclipse project generators in the global build.sbt file and it works for all my projects (or so it seems ;-)
I'm using Ubuntu, so where the SBT config files are saved on your computer may be different.
Create a folder called plugins under the hidden sbt directory. On Linux this is located at ~/.sbt (where tilde is an alias for your home directory). So now you should have ~/.sbt/plugins
Then create a file called build.sbt under this directory and add the following to it:
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases/"
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
To test, I just generated a scala 2.10 project with it, and it seems fine.
Oh, the file above also adds support for the eclipse command in SBT if you want to generate Scala-IDE projects.
I was able to use an older version of gen-idea by adding the following to project/plugins.sbt in the project itself:
import sbt._
import Defaults._
libraryDependencies += sbtPluginExtra(
m = "com.github.mpeltonen" % "sbt-idea" % "1.2.0", // Plugin module name and version
sbtV = "0.12", // SBT version
scalaV = "2.9.2" // Scala version compiled the plugin
)

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.