Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating the most basic Scala project with Maven?

Tags:

I use Maven 3 to create a new Scala project. As far as I understand, the way to create a new project with Maven is by:

mvn archetype:generate 

Maybe I'm missing out something, but I couldn't find even one option that offers the simplest Scala project (like the one received by lein new app ... for Clojure, for example). Any help here?

like image 801
shakedzy Avatar asked May 05 '16 09:05

shakedzy


People also ask

Can you build scala with maven?

The Scala Maven Plugin Note: the plugin includes Scala from the Central Repository so there's no need to install it yourself if you're compiling with Maven.

What is Scala with Maven?

Scala with Maven. Introduction. Maven is a build/project management tool. It favours “convention over configuration”; it can greatly simplify builds for “standard” projects and a Maven user can usually understand the structure of another Maven project just by looking at its pom.xml (Project Object Model).

Is SBT better than Maven for Scala?

I’ve worked in Scala for 6 years on projects ranging in size from 100s to 100k’s of LoC and built with SBT, Pants, and Maven. I recently surveyed the current state of these three tools and concluded that SBT is better suited than Maven to Scala projects’ needs.

How to use Scala in Java project?

now we can use scala in the project. for this purpose, you need to create two new folders — ‘ src/main/scala ‘ and ‘ src/test/scala ‘. the scala maven plugin looks at these directories and compiles scala files within them. import scala.collection.javaconversions._

How to run a Gatling simulation in Scala using Maven?

The project will use Maven for dependency management and to run a selected Gatling simulation. In the first step a Scala project that uses Maven for dependency management will be created and in the second step I will adapt the project to developing and running Gatling simulations.


1 Answers

You should be able to use mvn archetype:generate. You can choose, e.g., org.scala-tools.archetypes:scala-archetype-simple. You need to put in the number number next to the archetype name in the output of your mvn archetype:generate command because the numbering can change over time. There are also other options like eu.stratosphere:quickstart-scala as documented in this article.

They may be somewhat outdated, though. I personally prefer writing my pom.xml files manually. For reference, here is a minimal pom file for use with Scala 2.11.6 and Scalatest 2.2.5:

<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>com.example</groupId>   <artifactId>my-artifact</artifactId>   <version>1.0-SNAPSHOT</version>    <properties>     <encoding>UTF-8</encoding>     <scala.version>2.11.6</scala.version>   </properties>    <dependencies>     <dependency>       <groupId>org.scala-lang</groupId>       <artifactId>scala-library</artifactId>       <version>${scala.version}</version>     </dependency>      <dependency>       <groupId>org.scalatest</groupId>       <artifactId>scalatest_2.11</artifactId>       <version>2.2.5</version>       <scope>compile</scope>     </dependency>   </dependencies>    <build>     <plugins>       <plugin>         <groupId>org.scala-tools</groupId>         <artifactId>maven-scala-plugin</artifactId>         <version>2.15.2</version>         <executions>           <execution>             <goals>               <goal>compile</goal>               <goal>testCompile</goal>             </goals>           </execution>         </executions>       </plugin>        <plugin>         <groupId>org.scalatest</groupId>         <artifactId>scalatest-maven-plugin</artifactId>         <version>1.0</version>         <configuration>         </configuration>         <executions>           <execution>             <id>test</id>             <goals>               <goal>test</goal>             </goals>           </execution>         </executions>       </plugin>      </plugins>    </build> </project> 
like image 156
Mifeet Avatar answered Sep 22 '22 21:09

Mifeet