Restrikt
Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.
Install / Use
/learn @ZwenDo/RestriktREADME
Current features:
- Automatic way to hide symbols, with the automatic hiding of
internalsymbols. - Manual way to hide symbols, by using annotations to hide symbols from either Kotlin or Java sources.
- Possibility to use the
package-privatevisibility thanks to annotations. - Generation of private constructors for top-level classes.
Summary
Dependency
This compiler plugin offers some features working by detecting annotations on symbols. It allows you to define your own annotations, but also provides some default annotations recognized by the plugin. You can add them to your dependencies as regular dependencies.
[!NOTE] See the Plugin Configuration section for more information about the default annotations.
Kotlin version compatibility table
| Kotlin version | Plugin version |
|:--------------:|:----------------------------------:|
| prior to 2.0.0 | 4.0.0 <br/>(com.zwendo.restrikt) |
| 2.0.0 - 2.0.20 | 0.1.x |
| 2.1.0+ | 0.3.x |
Using Gradle
<details> <summary>Click to expand</summary>Using Kotlin DSL:
plugins {
id("com.zwendo.restrikt2") version "[latest-version]"
}
Using Groovy DSL:
plugins {
id 'com.zwendo.restrikt2' version '[latest-version]'
}
To add the default annotations to your project, you can add the following dependencies:
Using Kotlin DSL:
dependencies {
implementation("com.zwendo:restrikt2-annotations:[latest-version]")
}
Using Groovy DSL:
dependencies {
implementation 'com.zwendo:restrikt2-annotations:[latest-version]'
}
</details>
Using Maven
<details> <summary>Click to expand</summary>[!WARNING]
Maven support does not work at the moment. However, to use the plugin maven if the support is added, it should be as follows:
First of all, you need to add the compiler plugin to the kotlin's maven plugin dependencies:
<!-- ... -->
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>[kotlin-version]</version>
<!-- rest of the plugin configuration... -->
<dependencies>
<dependency>
<groupId>com.zwendo</groupId>
<artifactId>restrikt2-compiler-plugin</artifactId>
<version>[latest-version]</version>
</dependency>
</dependencies>
</plugin>
<!-- other plugins... -->
</plugins><!-- ... -->
The second step is to add the plugin id to the list of compiler plugins:
<!-- ... -->
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>[kotlin-version]</version>
<configuration>
<compilerPlugins>
<plugin>com.zwendo.restrikt2</plugin>
</compilerPlugins>
</configuration>
<!-- rest of the plugin configuration... -->
</plugin>
<!-- other plugins... -->
</plugins><!-- ... -->
Your pom.xml should look like this:
<project>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>[kotlin-version]</version>
<!-- ... -->
<configuration>
<compilerPlugins>
<plugin>com.zwendo.restrikt2</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>com.zwendo</groupId>
<artifactId>restrikt2-compiler-plugin</artifactId>
<version>[latest-version]</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
To add the default annotations to your project, you can add the following dependencies:
<dependencies>
<dependency>
<groupId>com.zwendo</groupId>
<artifactId>restrikt2-annotations</artifactId>
<version>[latest-version]</version>
</dependency>
</dependencies>
</details>
Using Kotlinc in the command line
<details> <summary>Click to expand</summary>To use the plugin with the Kotlin compiler, you simply need to add the plugin to the list of compiler plugins used in
your compilation process. It can be done by adding the following option to the kotlinc command:
-Xplugin=path/to/the/restrikt2-compiler-plugin.jar
Note that you might need to download the plugin jar. You can find it on the Maven Central Repository.
To the add default annotations to your project, you simply need to add the jars to the classpath of the compiler.
</details>Plugin Configuration
Available options
Here are the currently supported default configuration options:
| name | type | default | allow multiple occurrences | description |
|:------------------------------:|:-----------------------------:|:----------------------------:|:--------------------------:|---------------------------------------------------------------------------------------------------|
| enabled | boolean | true | false | Whether the plugin is enabled. |
| automatic-internal-hiding | boolean | true | false | Whether the internal symbols should be automatically hidden. |
| toplevel-private-constructor | boolean | true | false | Whether to generate private constructor for top-level classes. |
| annotation-processing | boolean | true | false | Whether the plugin annotations should be parsed to manually hide symbols. |
| hide-from-java-annotation | string (1) | none(2) | true | Adds an annotation to the annotations marking elements as hidden from Java. |
| hide-from-kotlin-annotation | string (1) | none(2) | true | Adds an annotation to the annotations marking elements as hidden from Kotlin. |
| package-private-annotation | string (1) | none(2) | true | Adds an annotation to the annotations marking elements as package-private. |
| ignore-default-annotations | boolean | false | false | Whether to ignore default marking annotations when processing annotations. (3) |
<a id="options-note-1"></a>
[!IMPORTANT]
Note 1: The syntax to add annotation with any option accepting an annotation is its fully qualified name where all packages are separated by a slash (/) and all inner classes are separated by a dot (.).Here are few examples:
- A
Fooannotation declared in thea.b.cpackage could be added witha/b/c/Foo.- A
Barannotation declared in theBaseclass itself in thebarpackage could be added withbar/Base.Bar.
<a id="options-note-2"></a>
Note 2: none means that no annotation is added by default,
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
