Sub topic 7
Version Numbers and the NEXT Keyword
This chapter assumes you can read sfdx-project.json, have a Dev Hub, and have already created a package with sf package create. It explains how a package version number is built and how the NEXT and LATEST keywords behave.
The four-part version number
Every package version has a number in the form major.minor.patch.build, for example 1.2.0.5.
| Part | Meaning | Who sets it |
|---|---|---|
| major | Large or breaking changes | You |
| minor | Backward-compatible features | You |
| patch | Small fixes | You |
| build | Counter for each version created | Salesforce, when you use `NEXT` |
In sfdx-project.json, the versionNumber field sets the number for the package directory. You write the first three parts yourself. For the fourth part you normally write NEXT.
{
"path": "force-app/core",
"package": "Core",
"versionName": "Spring release",
"versionNumber": "1.1.0.NEXT"
}What NEXT does
When you run sf package version create, Salesforce replaces NEXT with the next unused build number for that major.minor.patch combination. The first build of 1.1.0 is 1.1.0.1, the second is 1.1.0.2, and so on. You never edit the build number by hand, so two developers cannot create the same version by accident.
If you change the major, minor or patch part, the build counter starts again at 1. Building 1.2.0.NEXT gives 1.2.0.1, even if 1.1.0 reached build 7.
LATEST in dependencies
NEXT belongs to the package you are building. LATEST belongs to a dependency. In the Sales package, the entry { "package": "Core", "versionNumber": "1.0.0.LATEST" } means "the newest build of Core 1.0.0 that exists." Sales is then built against whichever Core build is newest at that moment.
Because of this, a rebuild of Sales can pick up a different Core build than last time. For repeatable builds, pin a dependency to an exact version, or use a package alias such as [email protected].
Version names and aliases
versionName is a free-text label such as "Spring release." It is for people, and it can stay the same across several builds. The number is what the platform uses. After a build, the CLI adds an alias like [email protected] to packageAliases. The part after the hyphen is the build number.
Common errors
- Version number already exists. You used a fixed build number, such as
1.1.0.1, that is already taken. Switch back toNEXT. - Number must be higher than released versions. Salesforce does not let you create a version with a number lower than one already promoted. Bump the minor or patch part.
- Unexpected dependency build. A
LATESTdependency moved to a newer build. Pin the version if you need stable results.
Exercise
Your project file has "versionNumber": "2.0.0.NEXT", and builds 2.0.0.1 through 2.0.0.4 exist. You change the file to 2.1.0.NEXT and build. What build number do you get, and why?
Show answer
You get 2.1.0.1. The build counter is tracked per major.minor.patch combination, so changing the minor part restarts it at 1.