Skip to content

Commit bc5c7a8

Browse files
authored
Docs: Improve docs for -library instruction (add examples)
Here is a suggested for improving the -library instruction. I have heard it being mentioned a couple of times. But I think the current documentation is missing some examples to illustrate the usefulness (as in "what can I do with it, and when would I use it"?) Signed-off-by: Christoph Rueger <[email protected]> Signed-off-by: Christoph Rueger <[email protected]>
1 parent 5549ecf commit bc5c7a8

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

docs/_instructions/library.md

+63-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,69 @@ title: -library library ( ',' library )*
55
summary: Apply a bnd library to the workspace, project, or bndrun file
66
---
77

8+
The main reason for the `-library` instruction is to let you package and share *bnd-related configuration* in a self-contained way so it can be reused across workspaces, projects, or run descriptions.
9+
10+
Let's use some examples for explanation.
11+
12+
## Example 1) Common bnd Configuration Across Multiple Projects
13+
14+
### Scenario
15+
16+
You have many projects that all need the same baseline OSGi or bnd settings—like default macros, a specific build plugin, or a certain analyzer configuration (e.g., “treat warnings as errors,” “export packages in a particular way,” etc.).
17+
18+
### How a Library Helps
19+
20+
1. Put these shared bnd instructions (i.e., the macros and plugin setups) in `project.bnd` (or `workspace.bnd`/`bndrun.bnd`) inside a “library bundle” in your repo.
21+
2. In each project that wants these settings, just add:
22+
```
23+
-library myconfig
24+
```
25+
3. All the macros and plugin instructions from that library will be included.
26+
27+
This avoids copying the same lines into each `bnd.bnd`. Instead, every project references the same library, ensuring consistency.
28+
29+
30+
## Example 2) Including Pre-Configured Tooling/Plugins
31+
32+
### Scenario
33+
You have a plugin (e.g., for code generation) that always needs a certain set of properties to work properly—maybe a specific source folder or some environment variables.
34+
35+
### How a Library Helps
36+
1. Provide a bundle that *contains* the plugin (or references it) plus a `bnd` file with the plugin’s configuration.
37+
2. Other projects include that library:
38+
```
39+
-library codegen
40+
```
41+
3. Now each project automatically has the plugin in its build plus the right plugin settings (class paths, macros, etc.).
42+
43+
This is particularly nice if you have multiple plugins or complex plugin settings that you do not want to replicate.
44+
45+
46+
## Creating a library
47+
48+
A _library_ is stored in a _bundle_. A bundle can contain multiple libraries that are each described by a
49+
capability in the `bnd.library` name space. This capability looks like:
50+
51+
Provide-Capability: \
52+
bnd.library; \
53+
bnd.library = foo; \
54+
version = 1.2.3; \
55+
path = lib/foo
56+
57+
The following attributes are defined for the `bnd.library` capabilities:
58+
59+
* `bnd.library` – The name of the library. Names should be kept simple but the names are shared between all libraries.
60+
* `version` – The version of the library.
61+
* `path` – A path to a directory in the bundle. The contents of this directory are the root of the library. This root
62+
is copied to the workspace cache.
63+
64+
The root of the library should contain the bnd files to be included. The defaults (`workspace.bnd`, `project.bnd`, and
65+
`bndrun.bnd`) should only be there if it makes sense to include the library in that type.
66+
67+
68+
69+
## Using a library
70+
871
A library can provide additional _named_ functionality to a workspace, a project, or a bndrun file. It does this by
972
including a `bnd` file in the setup that originates from a bundle in the repositories. This included bnd file
1073
can refer and use any binary resources in this bundle. Bundles can contain multiple libraries.
@@ -55,24 +118,3 @@ Projects and bndrun files can include libraries but they cannot define any new r
55118

56119
NOTE: what about standalone bndruns?
57120

58-
## Creating a library
59-
60-
A _library_ is stored in a _bundle_. A bundle can contain multiple libraries that are each described by a
61-
capability in the `bnd.library` name space. This capability looks like:
62-
63-
Provide-Capability: \
64-
bnd.library; \
65-
bnd.library = foo; \
66-
version = 1.2.3; \
67-
path = lib/foo
68-
69-
The following attributes are defined for the `bnd.library` capabilities:
70-
71-
* `bnd.library` – The name of the library. Names should be kept simple but the names are shared between all libraries.
72-
* `version` – The version of the library.
73-
* `path` – A path to a directory in the bundle. The contents of this directory are the root of the library. This root
74-
is copied to the workspace cache.
75-
76-
The root of the library should contain the bnd files to be included. The defaults (`workspace.bnd`, `project.bnd`, and
77-
`bndrun.bnd`) should only be there if it makes sense to include the library in that type.
78-

0 commit comments

Comments
 (0)