Skip to content

fix: ensure everything works and instructions updated #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java-version }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- uses: coursier/cache-action@v6

- name: Run project
run: ./mill root.run
run: ./mill examples.run
1 change: 1 addition & 0 deletions .mill-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.5
57 changes: 10 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,29 @@
# Example mill project that compiles using Scala 3

**NOTE**: Scala 3 support in mill is experimental. For now, sbt remains the
preferred option. See https://github.com/scala/scala3-example-project for an
example sbt project.

## Usage

This is a normal mill project. You can compile code with `mill root.compile` and run it
with `mill root.run`, `mill -i root.console` will start a Scala 3 REPL.
This is a normal mill project. You can compile code with `mill examples.compile` and run it
with `mill examples.run`, `mill -i examples.console` will start a Scala 3 REPL.

### IDE support

Scala 3 comes built-in with IDE support, unfortunately this support is only
available using sbt and not mill for now, see http://dotty.epfl.ch/docs/usage/ide-support.html
It's recommended to either use [Metals](https://scalameta.org/metals/) with the
editor of your choice or [the Scala Plugin for
IntelliJ](https://blog.jetbrains.com/scala/).

## Using Scala 3 in an existing project

### build.sc
Any version number that starts with `3.` is automatically recognized as Scala 3;
you don't need to set up anything:

```scala
def scalaVersion = "3.1.3"
```

#### Nightly builds

If the latest release of Scala 3 is missing a bugfix or feature you need, you may
wish to use a nightly build. Look at the bottom of the list of
[releases](https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/)
to find the version number for the latest nightly build.

## Getting your project to compile with Scala 3

When porting an existing project, it's a good idea to start out with the Scala 2
compatibility mode (note that this mode affects typechecking and thus may
prevent some valid Scala 3 code from compiling) by adding to your `build.sc`:

```scala
def scalacOptions = T {
if (Dep.isDotty(scalaVersion()))
Seq("-language:Scala2")
else
Seq()
}
```

Using the `Dep.isDotty` method ensures that this option will only be set when
compiling with Scala 3.

A tool to port code from Scala 2.x to Scala 3 is available; see
https://scalacenter.github.io/scala-3-migration-guide/docs/tooling/scala-3-migrate-plugin.html
### Getting your project to compile with Scala 3

If your build contains dependencies that have only been published for Scala 2.x,
you may be able to get them to work on Scala 3 by replacing:
For help with porting an existing Scala 2 project to Scala 3, see the
[Scala 3 migration guide](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html).

```scala
ivy"a::b:c"
```
## Need help?

by:

```scala
ivy"a::b:c".withDottyCompat(scalaVersion())
```
https://www.scala-lang.org/community/ has links.
Empty file removed build.sbt
Empty file.
4 changes: 1 addition & 3 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import mill._, scalalib._

object root extends SbtModule {
def millSourcePath = ammonite.ops.pwd
object examples extends ScalaModule {
def scalaVersion = "3.1.3"
def publishVersion = "0.1.0"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 19 additions & 7 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.9.7
DEFAULT_MILL_VERSION=0.10.5

set -e

if [ -z "$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then
elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=$DEFAULT_MILL_VERSION
fi
fi

MILL_DOWNLOAD_PATH="$HOME/.mill/download"
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION"
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

version_remainder="$MILL_VERSION"
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"

if [ ! -x "$MILL_EXEC_PATH" ] ; then
mkdir -p $MILL_DOWNLOAD_PATH
if [ ! -s "$MILL_EXEC_PATH" ] ; then
mkdir -p "$MILL_DOWNLOAD_PATH"
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION-assembly"
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
Expand Down
Empty file removed project/build.properties
Empty file.
Empty file removed project/plugins.sbt
Empty file.