I installed Ballerina Swan Lake 2201.7.2 and created a new Ballerina package using bal new hello
command. The main.bal
file contained the following code.
import ballerina/io;
public function main() {
io:println("Hello, World!");
}
Ballerina.toml
file content was as follows.
[package]
org = "demo"
name = "hello"
version = "0.1.0"
distribution = "2201.7.2"
[build-options]
observabilityIncluded = true
Then I ran the bal run
command and it gave the output successfully.
Compiling source
demo/hello:0.1.0
Running executable
Hello, World!
Then I changed my Ballerina Swan Lake version to 2201.6.1
using the bal dist use 2201.6.1
command.
After that, to compile and run the package with Ballerina Swan Lake version 2201.6.1
, I used the bal run
command. But it gave the following error.
Compiling source
demo/hello:0.1.0
ERROR [main.bal:(1:1,1:21)] cannot resolve module 'ballerina/io'
ERROR [main.bal:(4:5,4:32)] undefined function 'println'
ERROR [main.bal:(4:5,4:32)] undefined module 'io'
error: compilation contains errors
Why is that?
What Ballerina guarantees is that it will continue to support compiling packages using a higher Ballerina version that were already compiled with a lower Ballerina version, given that there are no backward incompatible changes introduced with the new releases. (Usually when there are backward incompatible changes, they are mentioned in the release note.)
There is no guarantee that the Ballerina packages compiled with a higher version of Ballerina will compile with a lower version of Ballerina due to the incompatible dependencies used by the package. For example, the above scenario can be explained as follows.
When compiling the program using Ballerina version 2201.7.2
, it creates the Dependencies.toml
file which contains the following.
# AUTO-GENERATED FILE. DO NOT MODIFY.
# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.
[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.7.2"
[[package]]
org = "ballerina"
name = "io"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]
modules = [
{org = "ballerina", packageName = "io", moduleName = "io"}
]
[[package]]
org = "ballerina"
name = "jballerina.java"
version = "0.0.0"
[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
[[package]]
org = "ballerina"
name = "observe"
version = "1.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
[[package]]
org = "ballerinai"
name = "observe"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]
[[package]]
org = "demo"
name = "hello"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "demo", packageName = "hello", moduleName = "hello"}
]
It shows the Ballerina package's dependencies and their minimum supported versions. For example, here Ballerina version 2201.7.2
requires at least io
version 1.5.0
.
When the package is then compiled with Ballerina version 2201.6.1
, it reads this Dependencies.toml
file and check whether this io
module version is supported by Ballerina version 2201.6.1
. When it doesn't it throws the above cannot resolve module 'ballerina/io'
error.
As a remedy, what you can do is deleting the Dependecies.toml
file created by the Ballerina version 2201.7.2
, and compile the package using the version 2201.6.1
. Then it will run the compile and run the code without any errors.
Compiling source
demo/hello:0.1.0
Running executable
Hello, World!
You can also see the below Dependencies.toml
file created with the version 2201.6.1
which says the Ballerina version requires at least io
version 1.4.1
. While io
version 1.4.1
falls within the compatible io
version ranges supported by the Ballerina version 2201.6.1
, io
version 1.5.0
is not supported by the Ballerina version 2201.6.1
. That's why the previous error occurred.
# AUTO-GENERATED FILE. DO NOT MODIFY.
# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.
[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.6.1"
[[package]]
org = "ballerina"
name = "io"
version = "1.4.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]
modules = [
{org = "ballerina", packageName = "io", moduleName = "io"}
]
[[package]]
org = "ballerina"
name = "jballerina.java"
version = "0.0.0"
[[package]]
org = "ballerina"
name = "lang.value"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
[[package]]
org = "ballerina"
name = "observe"
version = "1.0.7"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
[[package]]
org = "ballerinai"
name = "observe"
version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]
[[package]]
org = "demo"
name = "hello"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "demo", packageName = "hello", moduleName = "hello"}
]