Menu
  • HOME
  • TAGS

Cannot add scala swing dependency via Gradle in Scala IDE

Tag: scala,gradle,scala-ide,scala-swing

I am a beginner learning Scala. I am on Windows 8.1, using Scala IDE 4.0.0 and Gradle with scala and eclipse plugins to create a project, in which I want to use scala.swing and javax.media packages. I add both libraries as dependencies in build.gradle, only javax.media works.

The steps I have done are:

  1. create folders and files as follows

    foo
     |-src
        |-main
           |-scala
               |-Foo.scala
     |-build.gradle
    

    where build.gradle is Gradle build script and Foo.scala is a Scala script, as shown below

    <<build.gradle>>

    apply plugin: 'scala'
    apply plugin: 'eclipse'
    
    repositories {
      mavenCentral()
    }
    
    dependencies {
      compile 'org.scala-lang:scala-swing:2.10.4'
      compile 'javax.media:jmf:2.1.1e'
    }
    

    <<Foo.scala>>

    import javax.media.Player //no error
    import scala.swing._ //error: object swing is not a member of package scala
    
    class Foo {
    }
    
  2. using command line, navigate to foo and run gradle eclipse

  3. in Scala IDE, do import -> General -> Existing Projects into Workspace -> Browse -> Foo

Then, I get an error at Foo.scala, line 2, which reads object swing is not a member of package scala. And the Referenced Libraries list on the left panel shows only jmf-2.1.1e.jar for javax.media, as shown in the picture below

object swing is not a member of package scala

<<.classpath>>

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src/main/scala"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER" exported="true"/>
<classpathentry kind="lib" path="C:/Users/mm/.gradle/caches/modules-2/files-2.1/javax.media/jmf/2.1.1e/fe9287a362578bfb8b7b9dba42af0ec80a297abb/jmf-2.1.1e.jar" exported="true"/>
</classpath>

I have tried to configure Eclipse's build path and add scala-swing.jar manually, which works okay, but then I have to do this every time I run the Gradle build script. Please suggest why scala-swing-something.jar did not get imported by Gradle, and how to fix it.


This is the logging message after running $ gradle dependencies:

$ gradle dependencies
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

archives - Configuration for archive artifacts.
No dependencies

compile - Compile classpath for source set 'main'.
+--- org.scala-lang:scala-swing:2.10.4
|    \--- org.scala-lang:scala-library:2.10.4
\--- javax.media:jmf:2.1.1e

default - Configuration for default artifacts.
+--- org.scala-lang:scala-swing:2.10.4
|    \--- org.scala-lang:scala-library:2.10.4
\--- javax.media:jmf:2.1.1e

runtime - Runtime classpath for source set 'main'.
+--- org.scala-lang:scala-swing:2.10.4
|    \--- org.scala-lang:scala-library:2.10.4
\--- javax.media:jmf:2.1.1e

testCompile - Compile classpath for source set 'test'.
+--- org.scala-lang:scala-swing:2.10.4
|    \--- org.scala-lang:scala-library:2.10.4
\--- javax.media:jmf:2.1.1e

testRuntime - Runtime classpath for source set 'test'.
+--- org.scala-lang:scala-swing:2.10.4
|    \--- org.scala-lang:scala-library:2.10.4
\--- javax.media:jmf:2.1.1e

zinc - The Zinc incremental compiler to be used for this Scala project.
No dependencies

BUILD SUCCESSFUL

Total time: 11.159 secs

Best How To :

I had the same issue. I think it was an incompatibility between the Scala version and the Scala Swing version. I had these dependencies:

dependencies {
    compile 'org.scala-lang:scala-library:2.11.5'
    compile 'org.scala-lang:scala-swing:2.10.4'
}

To solve this, add the scala-library-all dependency instead:

dependencies {
    compile 'org.scala-lang:scala-library-all:2.11.5'
}

You can leave it at that, but it will add all sorts of dependencies that you might not need. If you don't want that, invoke:

gradle dependencies

It will tell you what dependencies Gradle has found. Mine said, among other things:

compile - Compile classpath for source set 'main'.
+--- org.scala-lang:scala-library-all:2.11.5
|    +--- org.scala-lang:scala-library:2.11.5
|    +--- org.scala-lang.modules:scala-swing_2.11:1.0.1
|    |    \--- org.scala-lang:scala-library:2.11.0 -> 2.11.5

Note the Scala Swing dependency, which has a different name and version from the one I had specified. Copy-and-paste that into your build.gradle dependencies:

dependencies {
    compile 'org.scala-lang:scala-library:2.11.5'
    compile 'org.scala-lang.modules:scala-swing_2.11:1.0.1'
}

And voilà:

gradle cleanEclipse eclipse

All dependencies work!

Retrieving TriangleCount

scala,apache-spark,spark-graphx

triangleCount counts number of triangles per vertex and returns Graph[Int,Int], so you have to extract vertices: scala> graph.triangleCount().vertices.collect() res0: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((1,1), (3,1), (2,1)) ...

implicit resolution for a function argument

scala,implicit,context-bound

You can overcome this by passing a function that calls mergesort to generalizedMergeSort. This call will capture the implicit Ordering: def mergesort[A: Ordering](as: List[A]): List[A] = { generalizedMergeSort(as, mergesort(_: List[A])) } mergesort(_: List[A]) is a closure function of type List[A] => List[A], which calls mergesort with its argument, and the...

Type to impose required constrains on a double

scala,implicit-conversion

This enabled basic run time checks: trait RangeBound type Probability = Double with RangeBound implicit def makeProb(p: Double): Probability = { assert (p >= 0.0 && p <= 1.0) p.asInstanceOf[Probability] } implicit val probabilityOrdering = Ordering.Double.asInstanceOf[Ordering[Probability]] ...

Operand order in Scala List.prepend (::)

list,scala,operators

Any operator with a : on its right side has its operands flipped. There's other operators that make use of this to (can't think of any examples off the top of my head though).

Passing a function foreach key of an Array

scala,apache-spark,scala-collections,spark-graphx

You're looking for the groupBy function followed by mapValues to process each group. pairs groupBy {_._1} mapValues { groupOfPairs => doSomething(groupOfPairs) } ...

Is this definition of a tail recursive fibonacci function tail-recursive?

scala,f#,functional-programming,tail-recursion,continuation-passing

The second call to go on line 4 is not in tail position, it is wrapped inside an anonymous function. (It is in tail position for that function, but not for go itself.) For continuation passing style you need Proper Tail Calls, which Scala unfortunately doesn't have. (In order to...

Scala rep separator for specific area of text

scala,parser-combinators

I guess you are using the RegexParsers (just note that it skips white spaces by default). I'm assuming that it ends with "\n\n--open--" instead (if you can change that otherwise I'll show you how to modify the repsep parser). With this change we see that the text has the following...

My Scala program won't print anything

scala

So, lots of problems. All that stuff you are doing? It's getting done in the constructor of Book, and redone for every instance. Your main method? That's gets compiled to instance method of Book, not a static method, so it does not serve an an entry point for an executable...

Scala unapplySeq extractor syntax

scala,pattern-matching,scala-2.11

The equivalent non-infix version is: xs match { case List(x, _, _) => "yes" case _ => "no" } Scala specification says: An infix operation pattern p;op;q is a shorthand for the constructor or extractor pattern op(p,q). The precedence and associativity of operators in patterns is the same as in...

Android studio gradle flavor dimensions build varients not working correctly

android-studio,gradle,android-gradle,build.gradle,android-productflavors

I think you misunderstood the concept of flavorDimension. A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant. In your case, you must define one flavorDimension named "type" and another dimension named "organization". It will produce, for each flavor...

Preventing a class instantiation in Scala using Factory Pattern [duplicate]

scala,factory-pattern

The conventional way to write a factory in Scala is to define an apply method on the companion object. Here's an example using Either (because null is never/rarely used in Scala, and exceptions are ugly): class A private (n: Int) { override def toString = s"A($n)" } object A {...

Scala slf4j dynamic file name

scala,logging,slf4j

The slf4j library is really an interface to some underlying logging implementation. You would have log4j, logback or some other logging implementation do the heavy lifting, with an adapter jar, as explained in the slf4j documentation. You would then provide the details in the properties file for log4j for instance,...

IntelliJ - use imported modules as dependencies like maven projects in Eclipse

eclipse,scala,maven,intellij-idea,sbt

It should work out of box for dependencies, which are imported to the project as modules, no additional settings needed. At least for Java. Just do not run a Maven goal, that would use dependencies from the repository. ...

refer to scala function by name?

scala

yyy is not a function, it's a method. You have to either convert it to a function using η-expansion yyy _ or use a function in the first place val yyy = (c: Char) => c.toUpper // or val yyy: Char => Char = c => c.toUpper // or val...

Scala (Slick) HList splitting to case classes

scala,slick

Using the tuple functionality in shapeless you could do: import shapeless._ import syntax.std.tuple._ case class Foo(a: Int, b: String) val hlist = 1 :: "a" :: 2 :: "b" :: HNil Foo.tupled(hlist.take(2).tupled) ...

How to effectively get indices of 1s for given binary string using Scala?

scala,functional-programming,higher-order-functions

You can use a filter and then map to get the index : scala> val s = "10010010" s: String = 10010010 scala> s.zipWithIndex.withFilter(_._1 == '1').map(_._2) res0: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 3, 6) Note: I'm using withFilter and not filter to avoid creating a temporary collection. Or you can use collect,...

Play Framework Form Error Handling

scala,playframework,playframework-2.3,playframework-2.4

Have a look at play documentation: Writing your own field constructor. You can check on errors with @if(elements.hasErrors) within the template of your custom field constructor. <div class="input-with-label text-left @if(elements.hasErrors){field-error}"> ... Edit: You can pass the error state of your field via the args parameter to your input. From the...

Scala running issue on eclipse

eclipse,scala

to run as scala application, you need to create Scala App and not class In eclipse, package explorer select project/src/package right click new>scala app inform Name e.g. Test and click "finish" select Test.scala right click "run as Scala Application" see results in console window....

How to reuse MappedColumnType in Table classes?

scala,playframework,slick

You could, for example, move it to a trait like this: trait DateColumnMapper extends HasDatabaseConfig[JdbcProfile] { protected val dbConfig: DatabaseConfig[JdbcProfile] import driver.api._ implicit val dateColumnType = MappedColumnType.base[Date, Long]( d => d.getTime, d => new Date(d) ) } Then you can include this trait in whatever DAO or db component you...

How to download a library dependence on gradle for external use?

cordova,android-studio,gradle,android-gradle,cordova-plugins

What you're looking for is an aar file. You can copy this file to lib folder with the following script: apply plugin: 'java' repositories { mavenCentral() } dependencies { compile 'io.filepicker:filepicker-android:[email protected]' } task copyLibs(type: Copy) { from configurations.compile into 'lib' } ...

How to instantiate lexical.Scanner in a JavaTokenParsers class?

scala,parsing,lexical-scanner

The JavaTokenParsers does not implement the Scanners trait. So you would need to extends also from this trait (or a trait that extends it) in order to have access to this class. Unless your expr parser accepts the Reader as a parameter (not from its apply method), you'd need to...

Scala - Option Type Var Manipulation

scala,scala-option

var balance = Some(0) is inferred to be of type Some[Int], when you need to tell this explicitly that it's of type Option[Int]: var balance: Option[Int] = Some(0) Then balance will be able to take in either Some(0) or None. By the way, it's sometimes a good practice to always...

Access key from mapValues or flatMapValues?

scala,apache-spark

In this case you can use mapPartitions with the preservesPartitioning attribute. x.map((it => it.map { case (k,rr) => (k, someFun(rr, k)) }), preservesPartitioning = true) You just have to make sure you are not changing the partitioning, i.e. don't change the key....

How to use Library from GitHub in android App

android,github,gradle,libraries

You have add path to your aFileDialog library in your settings.gradle Make sure that folder you point to includes build.gradle file include ':app' include ':aFileDialog' project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog') or (judging from the library folder structure on GitHub) project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog/library') ...

Implementing map on a tree using fold

scala,haskell

Try to write your last line as def map(tree:Tree[Int])(f:Int=>Int) : Tree[Int] = fold(tree , EmptyTree:Tree[Int])((l,x,r) => Node(f(x),l,r)) Scala's type inference is very limited compared to haskell, in this case it tries to infere type of fold from it's arguments left to right, and incorectly decides that result type of fold...

Is there any scala library that treat tuples as monads

scala,tuples,monads

Yep, Scalaz provides monad instances for tuples (up to Tuple8): import scalaz.std.anyVal._, scalaz.std.tuple._, scalaz.syntax.monad._ scala> type IntTuple[A] = (Int, A) defined type alias IntTuple scala> pair >>= (a => (a+1).point[IntTuple]) res0: (Int, String) = (2,as1) scala> for (p <- pair) yield (p + 1) res1: (Int, String) = (2,as1) (Note...

PlayFramework: value as is not a member of Array[Byte]

scala,playframework

You are calling the as method on the wrong object. It should look as follows: Ok(bytOfImage).as("image/jpg") ...

Spray route get response from child actor

scala,akka,spray

The first problem with your code is that you need to forward from the master actor to the child so that the sender is properly propagated and available for the child to respond to. So change this (in RedisActor): summaryActor ! msg To: summaryActor forward msg That's the primary issue....

Scala string replacement of entire words that comply with a pattern

string,scala,scala-collections,scala-string

You can use the \bth\w* pattern to look for words that begin with th followed by other word characters, and then replace all matches with "123" scala> "this is the example, that we think of, anne hathaway".replaceAll("\\bth\\w*", "123") res0: String = 123 is 123 example, 123 we 123 of, anne...

Zipping two arrays together with index in Scala?

arrays,scala,zip

Simply do: array1.zip(array2).zipWithIndex.map { case ((a, b), i) => (a, b, i) } ...

Spray microservice assembly deduplicate

scala,sbt,akka,spray,microservices

The issue as it seems transitive dependency of the dependency is resulting with two different versions of metrics-core. The best thing to do would be to used the right library dependency so that you end up with a single version of this library. Please use https://github.com/jrudolph/sbt-dependency-graph , if it is...

Scala, how to set up a node class?

scala

Algebraic data types break encapsulation by exposing the internal representation of the type publicly. When you take a functional programming point of view with regards to your design, then mutable state is not something that is a concern normally. Therefore, exposing the internal representation is not really a big deal...

Using ant.replace in gradle

replace,ant,gradle

It should be: task writeVersion << { ant.replace( file: 'version.txt', token: 'versionNumber', value: '1.0.0' ) } and: version.number=versionNumber ...

How to define a Regex in StandardTokenParsers to identify path?

regex,scala,parsing,lexical-analysis

In a double quoted string backslash is an escape character. If you mean to use the literal backslash in a double quotes string you must escape it, thus "\d" should be "\\d". Furthermore you do not need to escape the regex dot within a character class, since dot has no...

Paid and Free versions of android app

android,gradle,android-version

You could have two versions of the application in Play store. However, you would have to maintain these separately and it is frustrating to upgrade from free to paid with this approach. If you chose this way of maintaining your application, you would have to have two projects, one for...

Scala first program issue

scala,recursion,case,frequency

Cons operator (::) is an infix operator so if you want to get a type of List[T] and not List[List[T]] then you should write freq(c, y.filter(_ == c),(count(c,y),c)) :: list) ...

Collapse similar case statements in Scala

scala,functional-programming,pattern-matching

You can use a custom extractor to abstract the matching part away from the logic part: object Leafed { def unapply(tree: Tree) = tree match { case Node(Leaf(_, _), parent, qux) => Some((parent, qux)) case Node(parent, Leaf(_, _), qux) => Some((parent, qux)) case _ => None } } And then...

ZipList with Scalaz

list,scala,scalaz,applicative

pure for zip lists repeats the value forever, so it's not possible to define a zippy applicative instance for Scala's List (or for anything like lists). Scalaz does provide a Zip tag for Stream and the appropriate zippy applicative instance, but as far as I know it's still pretty broken....

Difficulty with SBT

scala,sbt

The %% in the dependency automatically appends a _2.XX scala version to your artifact id. It makes scala dependencies easier to manage, but you can't use it with java dependencies like apache httpcomponents. Instead just use %: "org.apache.httpcomponents" % "httpclient" % "4.5" ...

How to use the Akka ask pattern without blocking

scala,asynchronous,akka,future

You don't want to block, by waiting on the response of the actor, so you are using Future correctly. The code in the onComplete function is executed, when your actor responds with the list. And since you don't want to block and handle it asynchronously, your last println statement is...

Convert RDD[Map[String,Double]] to RDD[(String,Double)]

scala,apache-spark,rdd

You can call flatMap with the identity function to 'flatten' the structure of your RDD. rdd.flatMap(identity) ...

How to unmarshall akka http request entity as string?

json,scala,akka-http

Your code should be okay provided you have the right implicits in scope. If you have an implicit FlowMaterializer in scope then things should work as expected as this code that compiles shows: import akka.http.scaladsl.server.Route import akka.actor.ActorSystem import akka.stream.ActorFlowMaterializer import akka.http.scaladsl.model.StatusCodes._ import akka.http.scaladsl.server.Directives._ import akka.stream.FlowMaterializer implicit val system = ActorSystem("test")...

Android Studio and gradle

android,android-studio,gradle

So I have found the solution at this http://www.alonsoruibal.com/my-gradle-tips-and-tricks/. The trick is in your Java Library module's build.gradle file you need to include the following. apply plugin: 'java' sourceCompatibility = 1.6 targetCompatibility = 1.6 Wrong Java Compiler When Including a Java Module as Dependency in Android Studio...

Scodec: Coproducts could not find implicit value for parameter auto: scodec.codecs.CoproductBuilderAuto

scala,scodec

The code that is there now needs two minor changes: The Message trait must be sealed, or otherwise, Shapeless will not provide a Generic.Aux[Message, SomeCoproduct] instance. The call to Codec.coproduct[Message] must be after all the subtypes are defined. Moving the companion to the end of the file is sufficient. With...

Solving maze with Backtracking

scala,backtracking,maze

I'm only going to comment on findStart for now. There are two things wrong with findStart: findStart is recursively called on every adjacent cell. Unfortunately, the neighbouring cell of any neighbour is the cell itself. The function never checks if you can actually walk on a given cell (I assume...

Like clause not working with int column in slick

scala,slick,slick-2.0

Can you post your Status class definitation .If code is type column[Int] your code should be giving error as like works on column[string]. The below snippet works for doing a like on integer field. class Coffees(tag: Tag) extends Table[(String, Int)](tag, "COFFEES") { def name = column[String]("NAME") def status = column[Int]("STATUS")...

Future yielding with flatMap

scala

There's no reason to flatMap in the yield. It should be another line in the for-comprehension. for { a <- fa b <- fb c <- fc d <- f(a, b, c) } yield d I don't think it can get more concise than that....

Implicit Generic.Aux missing on conversion from Shapeless HList to case class

scala,shapeless,type-level-computation

You're very close. The problem is that Scala isn't going to propagate implicit requirements up the call chain automatically for you. If you need a Generic[A, T] instance to call convert, then you'll have to make sure that one's in scope every time you call convert convert. If A and...

How to generalize the round methods

scala

You could use the Numeric type class def round[T](input: T, scale: Int, f: BigDecimal => T)(implicit n: Numeric[T]): T = { f(BigDecimal(n.toDouble(input)).setScale(scale, RoundingMode.HALF_UP)) } Which can be used as: round(5.525, 2, _.doubleValue) res0: Double = 5.53 round(123456789L, -5, _.longValue) res1: Long = 123500000 Another way might be to create a...

SCALA: change the separator in Array

arrays,string,scala,delimiter

Your question is unclear, but I'll take a shot. To go from: val x = Array("a","x,y","b") to "a:x,y:b" You can use mkString: x.mkString(":") ...