[Java] IDEA Scala environment construction

Preface

I haven’t written a blog for a long time. Let’s write one for the time being. It’s not for any other reason, but as I write more and more blogs in the past, I feel more and more that a professional blog needs some systematic or refined things. I wrote it before Most of the content is just a running account and lacks depth. It only has breadth, which is far from enough.

Okay, no more gossip. This article mainly records the construction of the IDEA Scala environment.


Installing Scala on Windows

  • Download the Scala installation package

Insert image description herehttps://www.scala-lang.org/download/

Select the required version. https://www.scala-lang.org/download/2.12.17.html
Insert image description here
Download the zip package.
Insert image description here
Unzip the zip package. We cd to the corresponding directory and you can see that scala.batit is already an executable file. At this point we can configure environment variables to make use more convenient.
Insert image description here

  • Configure Scala path
    Insert image description here
    Insert image description here

First configureSCALA_HOME D:\develop\scala\apps\scala-2.11.12
Insert image description here

Then configure it into path. ( %SCALA_HOME%\bin)
Insert image description here

  • Test: scala -v
    Enter any directory and execute scala -v. You can see the results as shown below.
    Insert image description here

IDEA settings Scala plug-in & project settings Scala

  • Install scala plugin

setting -> Plugins -> Scala
Insert image description here

  • Create a simple Maven project. And add the following dependency packages.
    Insert image description here
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>scala-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <scala.binary.version>2.11</scala.binary.version>
        <scala.version>2.11.12</scala.version>
    </properties>


    <dependencies>

        <!-- Scala Library, provided by Flink as well. -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
            <!--			<scope>provided</scope>-->
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <!-- 声明绑定到maven的compile阶段 -->
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

The main ones are a scala-library. And a scala IDEA plug-in, which allows you to create Scala type files.

  • Add local scala address
    Project Structure --> Global Libraries -> 添加
    Insert image description here
    Insert image description here
  • After joining, you can find that IDEA can load scala Library.
    Insert image description here

Demo Helloword

  • Create the scala folder and set it to source root.
    Insert image description here
  • Create the corresponding package and set
    Insert image description here
    Insert image description here
package com.yanxml.scala.quick

object HelloWorld {
  def main(args: Array[String]): Unit = {
    System.out.print("Hello World")
  }
}

Insert image description here
Insert image description here


Reference

[1] IDEA 2020.3.X Detailed tutorial on creating scala environment

[2] How to build the Scala development environment of Intellij idea

[3] IDEA adds scala environment_IDEA builds scala development environment to develop spark applications (sample code)

[4] spark-Build scala programming environment in IDEA

[5] Scala project environment construction in idea

[6] IDEA configures scala development environment

Guess you like

Origin blog.csdn.net/u010416101/article/details/127505064
Recommended