How to add Jar libraries to an IntelliJ Idea SBT Scala project?

Viewed 35646

I've created an IntelliJ Idea SBT Scala project like Heiko Seeberger's article describes.

I'd like to add a Jar library (joda-time) to use in this project. How to do this? Simply putting them into project's /lib does not help. If I right-click "External libraries" in Idea's project tree, "New >" is greyed.

8 Answers

Create a lib directory in your project root path, paste your JARs in there, run sbt reload, close the project and open it again. Works for me in IntelliJ 2018.2.4 and SBT 1.0

Go to File -> Project Structure -> Modules

Select module in left pane and go to Dependencies tab

Click + to add JARs or directories

One way we can do is by adding jar explicitly in the Intellij but the problem with this approach is every time we build the project we need to add it again.

First way to do is :

In Intellij Idea:

File > Project Structure > Libraries

Another way is to publish the jar in local

Step 1 : Place the jar in any accessible folder.
Step 2 Create a build.sbt file which contains the detail of the jar.
Step 3 Open cmd to that path and execute command sbt publishLocal.
Step 4 Build your code and you would observe that you are able to access the classes belong to that jar.

build.sbt would look something like this:

organization := "com.abc.core"
name := "abc-test-logging"
version := "1.0-SNAPSHOT"
crossPaths := false
packageBin in Compile := file(s"${name.value}-${version.value}.jar")
Related