Skip to content

Commit 96fd9d4

Browse files
authored
Merge pull request #1892 from lwronski/dep-exclude
Add docs to classifiers and exclude dependency
2 parents bd3ac16 + 84feebe commit 96fd9d4

File tree

2 files changed

+102
-46
lines changed

2 files changed

+102
-46
lines changed

website/docs/guides/dependencies.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,58 @@ For example:
3636
org.postgresql:postgresql:42.2.8
3737
```
3838

39+
### Excluding Transitive Dependencies
40+
41+
To exclude a transitive dependency from a Scala CLI project use the `exclude` parameter:
42+
43+
- `exclude=org%%name` - for Scala modules
44+
- `exclude=org%name` - for Java modules
45+
46+
It requires passing the organization and module name of the dependency to be excluded. For example, let's say you have
47+
the following Scala code:
48+
49+
```scala title=Main.scala
50+
//> using dep "com.lihaoyi::pprint:0.8.1"
51+
object Main extends App {
52+
println("Hello")
53+
}
54+
```
55+
56+
If you want to compile it with the `pprint` library but exclude its `sourcecode` dependency, you can use
57+
the `exclude` parameter as follows:
58+
59+
```scala title=Main.scala
60+
//> using dep "com.lihaoyi::pprint:0.8.1,exclude=com.lihaoyi%%sourcecode"
61+
object Main extends App {
62+
println("Hello")
63+
}
64+
```
65+
66+
To exclude Scala modules, you can also use a single `%` but with the full name of the module name, like this:
67+
68+
```scala title=Main.scala
69+
//> using dep "com.lihaoyi::pprint:0.8.1,exclude=com.lihaoyi%sourcecode_3"
70+
object Main extends App {
71+
println("Hello")
72+
}
73+
```
74+
75+
76+
### Dependency classifiers
77+
78+
To specify a classifier of a dependency in a Scala CLI project, use the `classifier` parameter:
79+
80+
- `classifier={classifier_name}`
81+
82+
If you want to use the `pytorch` dependency with the classifier `linux-x86_64`, use the `classifier` parameter as follows:
83+
84+
```scala title=Main.scala
85+
//> using dep "org.bytedeco:pytorch:1.12.1-1.5.8,classifier=linux-x86_64"
86+
object Main extends App {
87+
println("Hello")
88+
}
89+
```
90+
3991
## Specifying dependencies from the command line
4092

4193
You can add dependencies on the command line, with the `--dependency` option:
@@ -72,49 +124,4 @@ Lastly, you can also add simple JAR files as dependencies with `--jar`:
72124

73125
```bash ignore
74126
scala-cli compile Sample.sc --jar /path/to/library.jar
75-
```
76-
77-
## Updating dependencies
78-
79-
To check if dependencies in using directives are up-to-date, use `dependency-update` command:
80-
81-
```scala title=Hello.scala
82-
//> using dep "com.lihaoyi::os-lib:0.7.8"
83-
//> using dep "com.lihaoyi::utest:0.7.10"
84-
85-
object Hello extends App {
86-
println("Hello World")
87-
}
88-
```
89-
90-
<ChainedSnippets>
91-
92-
```bash
93-
scala-cli --power dependency-update Hello.scala
94-
```
95-
96-
```text
97-
Updates
98-
* com.lihaoyi::os-lib:0.7.8 -> 0.8.1
99-
* com.lihaoyi::utest:0.7.10 -> 0.8.0
100-
To update all dependencies run:
101-
scala-cli dependency-update --all
102-
```
103-
104-
</ChainedSnippets>
105-
106-
Passing `--all` to the `dependency-update` sub-command updates all dependencies in your sources.
107-
108-
<ChainedSnippets>
109-
110-
```bash
111-
scala-cli --power dependency-update Hello.scala --all
112-
```
113-
114-
```text
115-
Updated dependency to: com.lihaoyi::os-lib:0.8.1
116-
Updated dependency to: com.lihaoyi::utest:0.8.0
117-
```
118-
119-
</ChainedSnippets>
120-
127+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Updating dependencies
3+
sidebar_position: 9
4+
---
5+
6+
import {ChainedSnippets} from "../../src/components/MarkdownComponents.js";
7+
8+
To check if dependencies in using directives are up-to-date, use `dependency-update` command:
9+
10+
```scala title=Hello.scala
11+
//> using dep "com.lihaoyi::os-lib:0.7.8"
12+
//> using dep "com.lihaoyi::utest:0.7.10"
13+
14+
object Hello extends App {
15+
println("Hello World")
16+
}
17+
```
18+
19+
<ChainedSnippets>
20+
21+
```bash
22+
scala-cli --power dependency-update Hello.scala
23+
```
24+
25+
```text
26+
Updates
27+
* com.lihaoyi::os-lib:0.7.8 -> 0.8.1
28+
* com.lihaoyi::utest:0.7.10 -> 0.8.0
29+
To update all dependencies run:
30+
scala-cli dependency-update --all
31+
```
32+
33+
</ChainedSnippets>
34+
35+
Passing `--all` to the `dependency-update` sub-command updates all dependencies in your sources.
36+
37+
<ChainedSnippets>
38+
39+
```bash
40+
scala-cli --power dependency-update Hello.scala --all
41+
```
42+
43+
```text
44+
Updated dependency to: com.lihaoyi::os-lib:0.8.1
45+
Updated dependency to: com.lihaoyi::utest:0.8.0
46+
```
47+
48+
</ChainedSnippets>
49+

0 commit comments

Comments
 (0)