Publishing a library
A library is code other projects use. Make one, then share it in either of two ways: from a Git repository, or as a
single .nylib file.
Make a library
In IntelliJ, choose File | New | Project…, then Nylon Library. Give it a name and a group, such as shapes and
org.example. It writes a build file that builds a library, and a starter file with one thing to share:
namespace org.example.shapes
# What a project that links this library may use: each declaration marked export.
export let answer(): i32 = 42
export marks what other projects can use. Everything else stays inside the library.
The build file names the library and its version:
(LibraryAssemblyBuild
name={"shapes"}
group={"org.example"}
version={"0.1.0"}
/LibraryAssemblyBuild)
A version is three numbers, major.minor.patch, and can carry a pre-release after a -, as in 0.2.0-rc.1. Raise it
each time you share a change. Build files has the
rest of what a build file takes.
Share it from Git
Push the project to a Git host, and tag the version you're sharing:
git tag v0.1.0
git push origin v0.1.0
To add it to another project, open the Nylon window, right-click Libraries, and choose Add Nylon Library from Git…:
- URL: the repository's address,
https://…orgit@host:path. - At: the tag you pushed. A branch works too, and so does a commit. With the default branch, the project follows the repository's newest work.
- Folder in the repository and Name are optional.
It adds one line to that project's build file:
(+dependencies let shapes : GitDependency url={"https://github.com/me/shapes.git"} tag={"v0.1.0"} /)
Reload Nylon Dependencies fetches the library and builds it, and it shows under Libraries in the Nylon window. A branch moves, so Reload fetches its newest commit again. A tag or a commit stays put.
Share it as a file
Choose Build | Build Project. It writes the library to the project's out/ folder as one file named after it,
shapes-0.1.0.nylib. Send that file to whoever needs it.
To add it to another project, right-click in the project view, choose Add Nylon Library from File…, and pick the
.nylib. It adds one line to the build file:
(+dependencies : FileDependency path={"libs/shapes-0.1.0.nylib"} /)
The path is from the build file's folder. A file is read as it is, so a newer version means a newer file.
Use it
The other project imports what it needs from the library's namespace, org.example.shapes, as it would from any
library. Libraries has more on importing, and on how
a build finds each library.