1
votes

I am trying to use LDAP via unboundid in scala but the compiler keeps crashing.

I just created an object that looks like this:

package utils

import com.unboundid.ldap.sdk._

object LdapHelper {
  val ldap = LDAPConnection("ldap.example.com", 389)
}

I added this: "com.unboundid" % "unboundid-ldapsdk" % "2.3.1" to my appDependencies in Build.scala. I use Play 2.1 and Scala Version 2.10.1.

I get a very strange error message (see below):

The error message is so strange that i really dont know where to begin to look for hints. Not sure if the problem is in unboundid, play, scala, sbt?

How can i successfully integrate unboundid in my scala project?

Thanks


Error in Scala compiler: assertion failed: while compiling: C:\play\todolist\app\utils\LdapHelper.scala during phase: global=typer, atPhase=parser library version: version 2.10.2 compiler version: version 2.10.2 reconstructed args: -classpath C:\play\todolist.target;C:\eclipse\scala-SDK-3.0.1-vfinal-2.10-win32.win32.x86_64\configuration\org.eclipse.

...

last tree to typer: Ident(LDAPConnection) symbol: (flags: ) symbol definition: symbol owners: context owners: value ldap -> object LdapHelper -> package utils

== Enclosing template or block ==

Template( // val : in object LdapHelper "java.lang.Object" // parents ValDef( private "_" ) // 3 statements DefDef( // def : in object LdapHelper "" [] List(Nil) Block( Apply( super."" Nil ) () ) ) DefDef( // def x: in object LdapHelper "x" [] Nil () ) ValDef( // private[this] val ldap: in object LdapHelper private "ldap" Apply( "LDAPConnection" // 2 arguments "ldap.example.com" 389 ) ) )

2

2 Answers

1
votes

There was a warning that turned into an assert in Scala 2.10.2 causing this.

There is a bug open here: https://issues.scala-lang.org/browse/SI-7014

And a fix staged for 2.10.4: https://github.com/scala/scala/pull/2829

You can ask Play to use Scala 2.10.4-SNAPSHOT by using the following Build.scala:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

    val appName         = "AppName"
    val appVersion      = "1.0-SNAPSHOT"

    val mainDeps = Seq(
      jdbc,
      anorm,
      cache
    )

    lazy  val main = play.Project(appName, appVersion, mainDeps).settings(
      scalaVersion := "2.10.4-SNAPSHOT"
    )

}

If you are using build.sbt the file would look like:

import play.Project._

playScalaSettings

name := "AppName"

version := "1.0-SNAPSHOT"

scalaVersion := "2.10.4-SNAPSHOT"

libraryDependencies ++= Seq(jdbc, anorm, cache) 

Note: if building from sbt (instead of play) you may have to add a repository resolver under the scalaVersion line such as: resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/repo/"

1
votes

The answer from @jeckhart works.

Firstly I use Scala 2.10.4-RC1 to build the Play 2.3 SNAPSHOT. Then use the output to compile with UnboundID.

Finally everything compiles with no assertion or error.

To build Play 2.3 SNAPSHOT using Scala 2.10.4-RC1, I modified the file framework/project/Build.scala.

Change these two section from

  val buildScalaVersion = propOr("scala.version", "2.10.3")
  val buildScalaVersionForSbt = propOr("play.sbt.scala.version", "2.10.3")

to

  val buildScalaVersion = propOr("scala.version", "2.10.4-RC1")
  val buildScalaVersionForSbt = propOr("play.sbt.scala.version", "2.10.4-RC1")