Scala development environment construction

At the beginning, I used eclipse development tools. After installing Scala, download the Scala Eclipse Plug-in and copy the feature s and plugin s in the compression package to the corresponding directory of eclipse tools. However, using Eclipse Maven to develop Scala projects is a bit of a pain. So, toss to toss to give up and use Idea to build Scala development environment.

Let's go to the official website to download the Scala Windows installation package, version 2.11.12. The installation process is like installing the JDK. Suppose we have installed Idea.

I. construction of Idea Scala environment

1. Search Scala on the right side of file - > setting - > plugins, and click Install to install Scala.

2. For a new Scala project, file - > New - > Project - > Scala, select IDEA. Next, and fill in the project name, Finish.

3. Create Scala Object and test Scala. (as you can see from the previous step, "the resource root directory is: src") create the package and Scala Object in the src directory.

II. Construction of Idea Scala Maven environment

1. Search Scala on the right side of file - > setting - > plugins, and click Install to install Scala.

2. For new Maven project, file - > New - > Project - > maven, check Create from archetype, select Scala archetype simple: 1.3, and click Next. Then, fill in the Maven project GroupId and ArtifactId, and click Next. Then, select the local Maven installation directory, click Next, and Finish.

3. After creating the project, fill in the pom.xml file, and then use Idea Maven to download and update Maven dependency (where we added Scala dependency and Slick dependency).

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.lv</groupId>
  <artifactId>scala-02</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>${project.artifactId}</name>
  <description>My wonderfull scala app</description>
  <inceptionYear>2010</inceptionYear>
  <licenses>
    <license>
      <name>My License</name>
      <url>http://....</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <properties>
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
    <encoding>UTF-8</encoding>
    <scala.version>2.11.12</scala.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <dependency>
      <groupId>com.typesafe.slick</groupId>
      <artifactId>slick_2.11</artifactId>
      <version>3.2.0</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <version>2.15.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <args>
                <arg>-make:transitive</arg>
                <arg>-dependencyfile</arg>
                <arg>${project.build.directory}/.scala_dependencies</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <useFile>false</useFile>
          <disableXmlReport>true</disableXmlReport>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

4. After Maven has finished downloading dependency, create Scala Object to test Scala program.

5. I made an error in executing Scala Object in the previous step when I was using it. The error is related to - make:transitive, so we need to modify:

So far, we have completed the construction of Scala Maven project!

Keywords: Big Data Scala Maven Eclipse Apache

Added by AjithTV on Mon, 09 Dec 2019 03:52:28 +0200