SkillAgentSearch skills...

Restrikt

Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Install / Use

/learn @ZwenDo/Restrikt
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<div align="center"> <h1>Restrikt 2.0</h1> <h4>Gradle Plugin</h4>

Gradle Plugin Portal

<h4>Compiler Plugin</h4>

Maven Central

<h4>Annotations</h4>

Maven Central

<h4>Others</h4>

Kotlin Java License

<h3><i>A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. Compatible with K2.</i></h3> </div> <br/>

Current features:

  • Automatic way to hide symbols, with the automatic hiding of internal symbols.
  • Manual way to hide symbols, by using annotations to hide symbols from either Kotlin or Java sources.
  • Possibility to use the package-private visibility thanks to annotations.
  • Generation of private constructors for top-level classes.

Summary

  1. Dependency
    1. Kotlin version compatibility table
    2. Gradle
    3. Maven
    4. Kotlin compiler
  2. Plugin Configuration
    1. Available options
    2. Gradle
    3. Maven
    4. Kotlin compiler
  3. Usage
    1. Internal symbols hiding
    2. Private constructors for Top-level classes
    3. 'Hide' Annotations
    4. PackagePrivate annotation
    5. Important notes
  4. Known issues
  5. How it works
  6. Future plans
  7. Changelog

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

[!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:

<details> <summary>Click to expand</summary>

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 Foo annotation declared in the a.b.c package could be added with a/b/c/Foo.
  • A Bar annotation declared in the Base class itself in the bar package could be added with bar/Base.Bar.

<a id="options-note-2"></a> Note 2: none means that no annotation is added by default,

Related Skills

View on GitHub
GitHub Stars40
CategoryDevelopment
Updated6mo ago
Forks0

Languages

Kotlin

Security Score

87/100

Audited on Oct 5, 2025

No findings