5

What a dotty build looks like?

 3 years ago
source link: https://blog.knoldus.com/what-a-dotty-build-looks-like/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What a dotty build looks like?

Reading Time: 3 minutes

Dotty is one of the most awaited change for scala developers. As we know its different then the Scala 2 in many ways. The major goals of this change are as follows:

  1. Making programming language compatible with the dot calculas and use lessons leart from that work.
  2. Making scala easier and safer to use. Remove wart and puzzlers.
  3. Improve consistency and expresiveness of Scala language constructs.

To know more about dotty, here is a beginers guide.

In this blog we will be setting up the local development environement to run dotty application.

While, starting working on dotty, you can start creating a sample project with dotty as I did and created a sample hello world project on my local system. Here in this blog, I am going to share the experience of creating my first dotty project and we will go throgh the findings and what problems I faced one by one with this blog.

Compling build.sbt file sucessfully:

I tried to create a build.sbt with most simple definition of a dotty project.
Here is the sample build.sbt file:

val dottyVersion = "0.24.0-RC1"

lazy val root = project
  .in(file("."))
  .settings(
    name := "my-dotty-sample",
    version := "0.1.0",

    scalaVersion := dottyVersion
  )

This is one of the error you might get during the compilation of project. This is because of the scala version.

To resolve this you need to update the plugins.sbt into project folder with dotty plugin as follows:

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1")

This is next error you might get, while compiling the project. This error might be there because of the sbt version. You need to use sbt version >= 1.3.6. Once you update the version if not already updated, this should be resolved.

Here is a link to download/update latest sbt version.

Note:

If you accedently compiled the build.sbt before update please update the build.properties file within project folder with latest version.

IDE Support:

The dotty provides support for visual studio. You can download the IDE from here and from the terminal just run the following command to get the IDE for dotty project:

sbt launchIDE

As result the IDE will be open:

Now you are ready to write your first program. Here is a sample main file for “Hello World” program. The file name is HelloWorldApp.scala

object HelloWorldApp extends App {

  println("Hello World!")

}

Running the application:

To run the application you can follow following steps:

1. Go to the project repo

2. Start SBT

> sbt

3. Run project using run command

sbt:my-dotty-sample> run

Here is the expected output:

Here you can find the sample project on git repo.

Congratulations! You are all set to explore dotty. In our next blog we will be exploring Dotty traits.

Thanks for reading.

References:

https://dotty.epfl.ch/docs/index.html

https://code.visualstudio.com/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK