Why does sbt think this is an 'unknown artifact?' - scala

I'm following the sbt directions here:
The instructions say to include this in my build.sbt file:
libraryDependencies += "org.apache.lucene" % "lucene-core" % "6.4.1"
But When I put that into IntelliJ, it gives the error: unresolved artifact. Not resolved or indexed. I'm new to Scala and SBT. Can someone help?

After you add library you need to refresh SBT project. you can move cursor to this error, and Option+Enter in mac or Alt+Enter in Windows/Linux for Refresh project. like:

Related

Why can't sbt find my local package

Searching for examples of library use I downloaded this project.
https://github.com/marcusatbang/Hooks
I then moved the build.bat up one directory. Commented out the xsbt-gpg dependency lines in build.sbt and Build.scala since sbt couldn't find the package. I checked the source to comment out any imports of xsbt-gpg -- there were none. ( Surprise! )
So I managed to compile the project. I then did sbt publish-local. find ~/.ivy2 -iname "\*hooks*jar" generated the following line: .ivy2/local/cc.minotaur/hooks_2.9.0/0.1/jars/hooks_2.9.0.jar.
I then entered the examples folder and tried to build the example project.
The build.scala contains the line: libraryDependencies += "cc.minotaur" %% "hooks" % "0.1", and it generates the error: unresolved dependency: cc.minotaur#hooks_2.9.1;0.1: not found
So how do I fix this error? It seems to me it should be finding the hooks jar/
That could be that your resolver doesn't see local directory. Try something like:
val ivyLocal = Resolver.file("local", file(Path.userHome.absolutePath +
"/.ivy2/local"))(Resolver.ivyStylePatterns)
externalResolvers += ivyLocal
It seems to me that you are using two versions of Scala. The one you are generating the jar is 2.9.0 while the one you are using in the example project is 2.9.1. Probably will solve the problem setting the same version in both projects.
I think your scala version is 2.9.1, u have generated jar for version 2.9.0
change your library dependency as mentioned below.
libraryDependencies += "cc.minotaur" % "hooks_2.9.0" % "0.1"
or add scalaVersion := "2.9.0" in your build.sbt file

Trouble adding Mapper as dependency in a Lift project

I am doing my first Lift project and want to add a database. Following a book, I added the following dependency to build.sbt:
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
And then, in Boot.scala, the import
import net.liftweb.mapper._
Now the project doesn't compile, with Boot.scala giving the error
object mapper is not a member of package net.liftweb
But other sources around the Internet seem to suggest that my imports are OK.
Where does the dependency problem come from?
It turned out that this is a problem of Eclipse, which cannot setup the dependencies correctly.
I had to close the project in Eclipse and delete the hidden files .classpath and .project. Then get into SBT and run
eclipse
(the project has to use the sbteclipse plugin as described in the Lift cookbook). This recreates the project files with the correct dependencies.
Afterwards, Eclipse compiled the code as expected. It seems this will be needed every time a change is made to build.sbt.

How to add a scala library to eclipse

I am trying to add this Scala Library into Eclipse so as to add available functions I can use on Actors.
I've downloaded the file and extracted it and tried adding it to my workspace in the project explorer, but when I try, Eclipse tells me it can't find any projects in the file. I'm sure that there is a tutorial or something online that explains exactly how to do this, but like I said, I'm not sure about all the terminology, so I don't know what to search for to get the result I want.
The easiest way is to create an sbt project and use the sbteclipse plugin.
Your project structure should look like this:
build.sbt
project/build.properties
project/eclipse.sbt
build.sbt
(note that lines of code should be separated by a white line)
name := "ProjectName"
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.2"
build.properties
sbt.version=0.13.5
eclipse.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
Then from the root directory execute sbt and within the sbt command line execute eclipse or eclipse with-sources=true
You can use sbt-extras or activator to get a specialized version that will automatically download the correct sbt version based on the build.properties file.
You could add the sbteclipse plugin as a default plugin, making it available in all projects by creating eclipse.sbt in the ~/.sbt/0.13/plugins directory instead of the project directory
If you created your project via sbt, please follow the instruction on the github page of async. Namely, add this libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.2" to build.sbt, run sbt, regenerate eclipse files with "eclipse" command and finally re-import project into eclipse

IntelliJ 13 with SBT plugin does not recognize Scalding dependency

I am trying to add Scalding 2.10 as a managed dependency via build.sbt like so:
name := "ss"
version := "1.0"
libraryDependencies += "com.twitter" % "scalding_2.10" % "0.10.0"
IntelliJ downloads the jar and adds it as an external library (see screen below) but fails to resolve the com.twitter namespace.
I have tried both invalidating the IntelliJ cache and generating project files via sbt gen-idea but neither solutions have worked. Any ideas would be greatly appreciated.
The scalding jar file scalding_2.10 has no code in it to compile against. Its just 300 Bytes in size.
The correct dependency I feel should be
libraryDependencies += "com.twitter" % "scalding-core_2.10" % "0.11.1"
As the comment suggest try rm-ing your ivy2 cache, and try sbt gen-idea. If that doesn't work, other things to check:
makes sure you have indeed got the scala plugin installed.
Most likely you're java SDK is not set or pointing somewhere wrong; right click the project dir, click "Open Module Settings", go to SDK and make sure the path is correctly set to the jdk otherwise syntax highlighting will likely break.
To test your deps have been properly pulled in from tinternet, try sbt compile; if it compiles then you should indeed have downloaded the dependency properly.

How can IntelliJ find remote dependencies?

I added the Mailer plugin to my Play Framework 2 project. It compiles and works fine, but IntelliJ can't resolve any of its classes. I would normally just add the jar as a module in my IntelliJ project settings, but I don't have a jar. As far as I understand, the plugin is automatically being pulled from some repository. So how do I make IntelliJ aware of it?
I added this to conf/play.plugins
1500:com.typesafe.plugin.CommonsMailerPlugin
And this as a dependency in project/build.scala
"com.typesafe" %% "play-plugins-mailer" % "2.0.4"
I resolve problems like this with the sbt-idea SBT plugin. Just add this to your project/plugins.sbt file:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
Then, whenever you change your project dependencies, run sbt idea and your IntelliJ project will be updated.
I had to delete the reference to com.github.mpeltonen in my plugins.sbt file first. Then as Bill said, I needed to run play idea. If I tried to run play idea without deleting the reference I got this exception:
java.lang.NoSuchMethodError: org.sbtidea.SbtIdeaPlugin$.ideaSettings()Lscala/collection/Seq;