How can I control the license agreement for my package's code?

← Getting Started · Ref: Q9

EK9 packages declare their license inside `defines package` using the `license` field. This is a String value that specifies the terms under which others may use your code.

Declare the license:

  license <- "MIT"

Common open source licenses:

  "MIT"            permissive, minimal restrictions
  "Apache-2.0"     permissive with patent grant
  "GPL-3.0"        copyleft, derivatives must also be GPL
  "BSD-2-Clause"   permissive, simple
  "LGPL-3.0"       copyleft for libraries, linking permitted
  "MPL-2.0"        file-level copyleft

For proprietary code:

  "Proprietary"    or your company's license name

The license field works together with `publicAccess`:

  publicAccess <- true     anyone can download and use
  publicAccess <- false    private, restricted distribution

A package with `publicAccess <- true` and `license <- "MIT"` tells consumers they can freely use, modify, and redistribute the code with attribution.

A package with `publicAccess <- false` and `license <- "Proprietary"` is restricted to authorized users only.

The license value is metadata: EK9 does not enforce license compliance at compile time. It is your responsibility to ensure your dependencies' licenses are compatible with your own. The `description` field can include additional terms if needed.

The code example below shows two typical licensing configurations.

See Q7 for managing dependencies. See Q8 for tagging packages.

Example

defines module qa.getting.started.package.licensing

  defines package

    version as Version: 1.0.0-0
    description as String = "Open source utility with MIT license"
    license <- "MIT"
    publicAccess <- true

    tags <- [
      "utility",
      "open-source"
    ]

    applyStandardIncludes <- true

  defines program
    PackageLicensing()
      stdout <- Stdout()

      stdout.println("Package license: MIT")
      stdout.println("Public access: true")
      stdout.println("Anyone can use, modify, and redistribute with attribution")

Common mistakes

E01040 — Defining two constructs with the same name in the same module triggers E01040 — duplicate construct. Each program name must be unique. See ek9 -h E01040 for details.

Incorrect:

defines program
    PackageLicensing()
      stdout <- Stdout()
    PackageLicensing()
      stdout <- Stdout()

Correct:

defines program
    PackageLicensing()
      stdout <- Stdout()
Other ways to ask this
  • How do I set a license on my EK9 package?
  • What licenses can I use for EK9 packages?
  • How does licensing work in defines package?
  • How do I make my EK9 code open source?
  • I set license in Cargo.toml or package.json, how do I do it in EK9?

Coming from another language?

Python: pyproject.toml license field or LICENSE file. Java: Maven pom.xml <licenses> section. Rust: Cargo.toml license field (SPDX identifier). npm: package.json license field. Go: LICENSE file by convention. EK9 uses a simple String field in the source file, similar to Rust's approach.

Keywords: publicAccess, intro, npm, terms, copyright, package, distribution, start, license, proprietary, open-source, cargo, MIT, beginner, spdx, first