Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the scala sdk using gradle in Idea module?

My build.gradle file

idea {
    project {
        vcs {
            vcs = 'Git'
        }

        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

I would also like to set the scala SDK in the module using gradle. Right now, I end up having to manually set it from Project Structure in the Idea UI. Ideally, I would prefer to set it in my build.gradle file such that when I run

gradle idea

the scala SDK is automatically set for this module

like image 338
Mathew Avatar asked Jan 20 '17 23:01

Mathew


People also ask

How do I run Scala with Gradle?

From inside the new project directory, run the init task using the following command in a terminal: gradle init . When prompted, select the 2: application project type and 5: Scala as implementation language. Next you can choose the DSL for writing buildscripts - 1 : Groovy or 2: Kotlin .

How do I enable Scala in IntelliJ?

To install Scala plugin, press Ctrl+Alt+S , open the Plugins page, browse repositories to locate the Scala plugin, click Install and restart IntelliJ IDEA. Now you can successfully check out from VCS, create, or import Scala projects.


2 Answers

To have a project with scala module in Intellij using gradle,

  1. Create a new IDEA based scala project enter image description here
  2. Give appropriate project name and proceed.
  3. Next, check if you've gradle in your local environment. (Install gradle using $sudo apt install gradle and then use command $which gradle to find location of gradle)
  4. Open your terminal and navigate to your project directory. Execute command $gradle init --type scala-library This will make your project gradle based and you'll see associated gradle files in Intellij.
  5. Restart Intellij and navigate to View > Tool Windows > Gradle to see Gradle tab.
like image 136
Aman Sehgal Avatar answered Sep 19 '22 13:09

Aman Sehgal


From the Gradle documentation for the Scala plugin, you must add the Scala library dependency to the compile class path. For example:

compile "org.scala-lang:scala-library:2.12.4"
compile "org.scala-lang:scala-reflect:2.12.4"

For integration with IntelliJ IDEA, you can apply the idea plugin:

apply plugin: 'idea'

Adding the Scala library to the compile class path is required even if your source is in test code only. After this, IntelliJ will automatically set up the Scala SDK for you.

like image 38
cstroe Avatar answered Sep 19 '22 13:09

cstroe