You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/creating-packages.md
+60-47Lines changed: 60 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -275,58 +275,37 @@ test-specific dependencies, are available, see below.
275
275
276
276
### Test-specific dependencies
277
277
278
-
There are two ways of adding test-specific dependencies (dependencies that are not dependencies of the package but will still be available to
279
-
load when the package is tested).
278
+
Test-specific dependencies are dependencies that are not dependencies of the package itself but are available when the package is tested.
280
279
281
-
#### `target` based test specific dependencies
280
+
#### Recommended approach: Using workspaces with `test/Project.toml`
282
281
283
-
Using this method of adding test-specific dependencies, the packages are added under an `[extras]` section and to a test target,
284
-
e.g. to add `Markdown` and `Test` as test dependencies, add the following to the `Project.toml` file:
285
-
286
-
```toml
287
-
[extras]
288
-
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
289
-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
290
-
291
-
[targets]
292
-
test = ["Markdown", "Test"]
293
-
```
294
-
295
-
Note that the only supported targets are `test` and `build`, the latter of which (not recommended) can be used
296
-
for any `deps/build.jl` scripts.
282
+
!!! compat
283
+
Workspaces require Julia 1.12+. For older Julia versions, see the legacy approaches below.
297
284
298
-
#### Alternative approach: `test/Project.toml` file testspecific dependencies
285
+
The recommended way to add test-specific dependencies is to use workspaces. This is done by:
299
286
300
-
!!! note
301
-
The exact interaction between `Project.toml`, `test/Project.toml` and their corresponding
302
-
`Manifest.toml`s are not fully worked out and may be subject to change in future versions.
303
-
The older method of adding test-specific dependencies, described in the previous section,
304
-
will therefore be supported throughout all Julia 1.X releases.
287
+
1. Adding a `[workspace]` section to your package's `Project.toml`:
305
288
306
-
In Julia 1.2 and later test dependencies can be declared in `test/Project.toml`. When running
307
-
tests, Pkg will automatically merge this and the package Projects to create the test environment.
308
-
309
-
!!! note
310
-
If no `test/Project.toml` exists Pkg will use the `target` based test specific dependencies.
289
+
```toml
290
+
[workspace]
291
+
projects = ["test"]
292
+
```
311
293
312
-
To add a test-specific dependency, i.e. a dependency that is available only when testing,
313
-
it is thus enough to add this dependency to the `test/Project.toml` project. This can be
314
-
done from the Pkg REPL by activating this environment, and then use `add` as one normally
315
-
does. Let's add the `Test` standard library as a test dependency:
294
+
2. Creating a `test/Project.toml` file with your test dependencies:
316
295
317
296
```julia-repl
318
297
(HelloWorld) pkg> activate ./test
319
298
[ Info: activating environment at `~/HelloWorld/test/Project.toml`.
320
299
321
-
(test) pkg> add Test
300
+
(HelloWorld/test) pkg> add Test
322
301
Resolving package versions...
323
302
Updating `~/HelloWorld/test/Project.toml`
324
303
[8dfed614] + Test
325
-
Updating `~/HelloWorld/test/Manifest.toml`
326
-
[...]
327
304
```
328
305
329
-
We can now use `Test` in the test script and we can see that it gets installed when testing:
306
+
When using workspaces, the package manager resolves dependencies for all projects in the workspace together, and creates a single `Manifest.toml` next to the base `Project.toml`. This provides better dependency resolution and makes it easier to manage test-specific dependencies.
Workspaces can also be used for other purposes, such as documentation or benchmarks, by adding additional projects to the workspace:
326
+
327
+
```toml
328
+
[workspace]
329
+
projects = ["test", "docs", "benchmarks"]
349
330
```
350
331
332
+
See the section on [Workspaces](@ref) in the `Project.toml` documentation for more details.
333
+
334
+
#### Legacy approach: `target` based test specific dependencies
335
+
336
+
!!! warning
337
+
This approach is legacy and maintained for compatibility. New packages should use workspaces instead.
338
+
339
+
Using this method, test-specific dependencies are added under an `[extras]` section and to a test target:
340
+
341
+
```toml
342
+
[extras]
343
+
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
344
+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
345
+
346
+
[targets]
347
+
test = ["Markdown", "Test"]
348
+
```
349
+
350
+
Note that the only supported targets are `test` and `build`, the latter of which (not recommended) can be used for any `deps/build.jl` scripts.
351
+
352
+
#### Legacy approach: `test/Project.toml` without workspace
353
+
354
+
!!! warning
355
+
This approach is legacy and maintained for compatibility. New packages should use workspaces instead.
356
+
357
+
In Julia 1.2 and later, test dependencies can be declared in `test/Project.toml` without using a workspace. When running tests, Pkg will automatically merge the package and test projects to create the test environment.
358
+
359
+
!!! note
360
+
If no `test/Project.toml` exists, Pkg will use the `target` based test specific dependencies.
361
+
362
+
This approach works similarly to the workspace approach, but without the workspace declaration in the main `Project.toml`.
363
+
351
364
## Compatibility on dependencies
352
365
353
366
Every dependency should in general have a compatibility constraint on it.
@@ -450,9 +463,7 @@ Extensions can have arbitrary names (here `ContourExt`), following the format of
450
463
In `Pkg` output, extension names are always shown together with their parent package name.
451
464
452
465
!!! compat
453
-
Often you will put the extension dependencies into the `test` target so they are loaded when running e.g. `Pkg.test()`. On earlier Julia versions
454
-
this requires you to also put the package in the `[extras]` section. This is unfortunate but the project verifier on older Julia versions will
455
-
complain if this is not done.
466
+
Often you will want to load extension dependencies when testing your package. The recommended approach is to use workspaces and add the extension dependencies to your `test/Project.toml` (see [Test-specific dependencies](@ref adding-tests-to-packages)). For older Julia versions that don't support workspaces, you can put the extension dependencies into the `test` target, which requires you to also put the package in the `[extras]` section. The project verifier on older Julia versions will complain if this is not done.
456
467
457
468
!!! note
458
469
If you use a manifest generated by a Julia version that does not know about extensions with a Julia version that does
@@ -557,11 +568,13 @@ This is done by making the following changes (using the example above):
557
568
558
569
In the case where one wants to use an extension (without worrying about the
559
570
feature of the extension being available on older Julia versions) while still
560
-
supporting older Julia versions the packages under `[weakdeps]` should be
571
+
supporting older Julia versions without workspace support, the packages under `[weakdeps]` should be
561
572
duplicated into `[extras]`. This is an unfortunate duplication, but without
562
573
doing this the project verifier under older Julia versions will throw an error
563
574
if it finds packages under `[compat]` that is not listed in `[extras]`.
564
575
576
+
For Julia 1.13+, using workspaces is recommended and this duplication is not necessary.
577
+
565
578
## Package naming guidelines
566
579
567
580
Package names should be sensible to most Julia users, *even to those who are not domain experts*.
This structure is particularly beneficial for developers using a monorepo approach, where a large number of unregistered packages may be involved. It's also useful for adding documentation or benchmarks to a package by including additional dependencies beyond those of the package itself.
207
+
This structure is particularly beneficial for developers using a monorepo approach, where a large number of unregistered packages may be involved. It's also useful for adding test-specific dependencies to a package by including a `test` project in the workspace (see [Test-specific dependencies](@ref adding-tests-to-packages)), or for adding documentation or benchmarks with their own dependencies.
208
208
209
209
Workspace can be nested: a project that itself defines a workspace can also be part of another workspace.
210
210
In this case, the workspaces are "merged" with a single manifest being stored alongside the "root project" (the project that doesn't have another workspace including it).
0 commit comments