Thursday, June 15, 2017

Create a scala project using maven on intellij

  • Download and install intellij
  • Install scala plugin
    • Configure -> Plugins -> Browsw repositories... -> search scala -> select scala -> Install -> restart intellij
  • Create a maven project
    • Crete New Project -> Maven -> New -> select SDK -> Create from archetype
    • Add Archetype...
      • <dependency>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-archetype-simple</artifactId>
        <version>1.6</version>
        </dependency>
    • net.alchim31.maven:scala-archetype-simple -> Next -> Input information about GroupId, ArtifactId and Version -> Next -> Next -> change Project location -> Finish
    • Enable Auto-Import
  • Testing
    • remove "<arg>-make:transitive</arg>" from pom.xml
    • test -> scala -> samples -> specs.scala -> add "import org.scalatest.junit.JUnitRunner"
    • src -> main -> scala -> $package -> App -> Ctrl + Shift + F10
  • Sample pom.xml
    • <?xml version="1.0" encoding="UTF-8"?>
       
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.netmarble.columbus</groupId>
        <artifactId>test</artifactId>
        <version>1.0.0-SNAPSHOT</version>
       
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
          <java.version>1.8</java.version>
          <scala.version>2.11.8</scala.version>
          <scala.binary.version>2.11</scala.binary.version>
          <spark.version>2.0.0</spark.version>
        </properties>
       
        <dependencies>
          <!-- Scala -->
          <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-actors</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scalap</artifactId>
            <version>${scala.version}</version>
            <scope>provided</scope>
          </dependency>
       
          <!-- Spark -->
          <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
          </dependency>
       
          <!-- Test -->
          <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.binary.version}</artifactId>
            <version>2.2.6</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>org.scalacheck</groupId>
            <artifactId>scalacheck_${scala.binary.version}</artifactId>
            <version>1.12.5</version<!-- 1.13.0 appears incompatible with scalatest 2.2.6 -->
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
          </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.2</version>
              <executions>
                <execution>
                  <goals>
                  <goal>compile</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>3.0.0</version>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </project>
  • Reference for pom.xml

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.