wso2/strict.library

0.9.0
Ballerina Strict Library

Build GitHub Last Commit License

The wso2/strict.library package provides compile-time validation for Ballerina library projects. It ensures that library packages do not contain executable entrypoints, enforcing a clean separation between reusable library code and application logic.

Usage

Add the import to any .bal file in your library project. The conventional place is a dedicated lib.bal:

Copy
import wso2/strict.library as _;

The compiler plugin activates automatically during compilation — no additional configuration is needed. Once active, it scans all source files in the default module for prohibited constructs.

What Is Validated

The following constructs are not allowed in a library project:

ConstructExample
Public main functionpublic function main() { }
Module init functionfunction init() { }
Service declarationservice / on ep { }
Listener declarationlistener http:Listener ep = new(8080);

If any are detected, compilation fails with diagnostic code STRICT_LIBRARY_101:

error [STRICT_LIBRARY_101]: library projects must not contain entrypoints. Found: 'public function main' in main.bal

Multiple violations are combined into a single error, listing each with the file where it was found.

Why Use This

Library packages expose reusable functions, types, and classes for other Ballerina projects. Including entrypoints like main, services, or listeners in a library is typically a mistake and can cause unexpected behavior when the package is used as a dependency. This module catches those mistakes at compile time, before they can affect downstream consumers.

Issues and Projects

The Issues and Projects tabs are used to track work on this module.

Building from Source

Copy
git clone https://github.com/wso2/ballerina-module-strict-library.git
cd ballerina-module-strict-library
./gradlew build
./gradlew :strict-library-compiler-plugin-tests:test

Contributing

Contributions are welcome. See the contribution guidelines for more information.

License

This project is licensed under the Apache License 2.0.

Import

import wso2/strict.library;Copy

Other versions

0.9.0

Metadata

Released date: 3 months ago

Version: 0.9.0

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.13.0

GraalVM compatible: Yes


Pull count

Total: 171

Current verison: 171


Weekly downloads


Source repository


Keywords

library

validation


Contributors