mikolak-net / scala-quickstart-archetype

Basic general-purpose Scala archetype.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scala-quickstart-archetype

Introduction

An uncomplicated Scala archetype. Has the following features:

  • minimizes the amount of "example" files that you would have to delete anyway (cf. maven-quickstart-archetype).

  • automatically creates empty package directories for main and test.

  • lets you choose your source folder structure.

    • all applicable structure options allow for mixed Java-Scala development.

    • has a sensible default where everything is in src/main/java (allows for IDEs to play nicely).

  • lets you choose your favorite test library.

The general goal of this archetype is to provide a minimum-cruft, customizable ability to create Java/Scala and pure Scala Maven projects.

Options

  • sourceFolders: [all-in-src-java, scala-only, both-split-src]. DEFAULT: all-in-src-java.

    • all-in-src-java: Scala and Java code are both in src/main/java (same for test). Plays nicely with IDEs.

    • scala-only: only src/main/scala set up, and set as source folder.

    • both-split-src: both src/main/java and src/main/scala. Can wreak havoc with IDEs, so not the default.

  • testLibrary: [scalatest, specs2, scalacheck-only, junit-only]. DEFAULT: scalatest.

    • scalatest: adds Scalatest AND Scalacheck AND JUnit for most of your testing needs.

    • specs2: adds specs2 AND Scalacheck AND JUnit.

    • scalacheck-junit: adds Scalacheck AND JUnit.

    • junit-only: adds JUnit ONLY.

  • scalaVersion: 2.10.x+. DEFAULT: 2.11.2.

Note
The Scala tool version is generated automatically.
Note
Some Scala versions may not be compatible with selected test library versions. Adjust as necessary.

Usage

Analogous to maven-quickstart-archetype. Since the archetype is now on Maven Central, you don’t need to download anything.

CLI

Batch

mvn archetype:generate -B \
 -DarchetypeGroupId=pl.org.miki -DarchetypeArtifactId=scala-quickstart-archetype -DarchetypeVersion=0.8.2 \
 -DgroupId=com.example -DartifactId=project -Dversion=1.0 -Dpackage=com.example.project \
 -DsourceFolders: [all-in-src-java, scala-only, both-split-src] \ #optional
 -DtestLibrary: [scalatest, specs2, scalacheck-only, junit-only] #optional

Interactive

cd x #where x is your "workspace" directory
mvn archetype:generate
#filter by e.g. "scala-quickstart", or gId:aId, which is pl.org.miki:scala-quickstart-archetype
#input artifactId etc.

IDE

Eclipse

  1. New …​  Project…​  Maven  Maven Project  Next.

  2. Filter for {artifactId}. Next.

  3. Fill out the necessary values (see Options for more info). Finish

IntelliJ IDEA

  1. Create New Project  Maven.

  2. Check Create from archetype.

  3. On first generation only: Add Archetype…​

    1. GroupID = {groupId}

    2. ArtifactId = {artifactId}

    3. Version = {version}

  4. Select the {artifactId} archetype from the list. Next.

  5. Enter the Maven coordinates of your project. Next.

  6. Add {optionLineInteractive} to the options (see Options for more info).

  7. Fill out remaining details and Finish.

Why yet another archetype?

An excellent question! First of all, archetypes are sometimes quite underrated as a concept - they provide a gateway to various technologies and frameworks to coders who are not Maven, er, mavens.

Given that, let’s take a look at some "generic" archetypes such as net.alchim31.maven:scala-archetype-simple or org.apache.maven.archetypes:maven-archetype-quickstart. After project creation, it becomes apparent that they serve mainly the following purposes:

  • creating the POM boilerplate for the specific project type,

  • introducing the POM creator to some associated frameworks, technologies and/or patterns (e.g. the Scala archetype includes no less than three different test libraries at the same time).

At this point, coupled with the premise that POMs are essentially executable (declarative) build configuration code, it can be argued that the aforementioned archetypes fail the SRP.

The archetype you’re now viewing, and its sister project, attempt to alleviate this problem.

Namely, they have a single goal in mind: enable a user to create multiple projects, with the most popular exclusive configuration variants, and with the least "educto-boilerplate" to clean up.

The last subpoint emphasizes why this goal was chosen as a primary one, over educating newcomers.

Nowadays, various 3rd party ecosystem libs (such as the aforementioned three testing libraries ) tend to do a decent job at introducing new developers. Therefore, it is posited that it’s more efficient for an archetype to just focus on providing a tabula rasa.

About

Basic general-purpose Scala archetype.

License:BSD 3-Clause "New" or "Revised" License