Skip to content

Commit 7f0b764

Browse files
committed
Improve dependencies doc
1 parent 7b81867 commit 7f0b764

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

website/docs/guides/dependencies.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,74 @@ title: Managing dependencies
33
sidebar_position: 9
44
---
55

6-
# Dependencies
6+
# Managing dependencies
7+
8+
## Dependency syntax
9+
10+
Dependencies are declared in Scala CLI according to the following format:
11+
12+
```text
13+
groupID:artifactID:revision
14+
```
15+
16+
This is similar to how you declare dependencies in SBT with the `%` character.
17+
For example:
18+
19+
```text
20+
org.scala-lang.modules:scala-parallel-collections_2.13:1.0.4
21+
```
22+
23+
You can also skip explicitly stating the Scala version in the artifact name by repeating the `:` character after
24+
the `groupID` (similarly to how you can do the same with `%%` in SBT). This is just a shortcut, Scala CLI will still add
25+
the Scala version for you when fetching the dependency. Also, this only applies to Scala dependencies.
26+
27+
```text
28+
org.scala-lang.modules::scala-parallel-collections:1.0.4
29+
```
30+
31+
Java and other non-scala dependencies follow the same syntax (without the `::` for implicit Scala version, of course).
32+
For example:
33+
```text
34+
org.postgresql:postgresql:42.2.8
35+
```
36+
37+
## Specifying dependencies from the command line
738

839
You can add dependencies on the command line, with the `--dependency` option:
40+
941
```bash
1042
scala-cli compile Hello.scala \
1143
--dependency org.scala-lang.modules::scala-parallel-collections:1.0.4
1244
```
1345

1446
You can also add a URL fallback for a JAR dependency, if it can't be fetched otherwise:
47+
1548
```bash
1649
scala-cli compile Hello.scala \
1750
-- dependency "org::name::version,url=https://url-to-the-jar"
1851
```
1952

20-
Note that `--dependency` is only meant as a convenience.
21-
You should favor adding dependencies in the sources themselves via [using directives](/docs/guides/configuration.md#special-imports).
22-
<!-- TODO #344
23-
However, `--dependency` CLI option takes precedence over `using` directives, so it can be used to override the `using` directive, such as when you want to work with a different dependency version. -->
53+
Note that `--dependency` is only meant as a convenience. You should favor adding dependencies in the sources themselves
54+
via [using directives](/docs/guides/configuration.md#special-imports). However, the `--dependency` CLI option takes
55+
precedence over `using` directives, so it can be used to override a `using` directive, such as when you want to work
56+
with a different dependency version.
2457

2558
You can also add repositories on the command-line, via `--repository`:
59+
2660
```bash
2761
scala-cli compile Hello.scala \
2862
--dependency com.pany::util:33.1.0 --repo https://artifacts.pany.com/maven
2963
```
3064

3165
Lastly, you can also add simple JAR files as dependencies with `--jar`:
66+
3267
```bash
3368
scala-cli compile Hello.scala --jar /path/to/library.jar
3469
```
3570

36-
## Update dependencies
71+
## Updating dependencies
3772

38-
To check if dependencies in using directives are up to date use `dependency-update` command:
73+
To check if dependencies in using directives are up-to-date, use `dependency-update` command:
3974

4075
```scala title=Hello.scala
4176
//> using lib "com.lihaoyi::os-lib:0.7.8"

0 commit comments

Comments
 (0)