hikage-gradle-plugin

Maven CentralMaven metadata URL

This is the Gradle plugin of Hikage, which contains the core capabilities of Hikage.

Configure Plugin

You can add this plugin to your project using the following method.

Add plugin in your project's gradle/libs.versions.toml.

[versions]
hikage-plugin = "<version>"

[plugins]
hikage = { id = "com.highcapable.hikage", version.ref = "hikage-plugin" }

Apply plugin in your project's build.gradle.kts.

plugins {
    // ...
    alias(libs.plugins.hikage)
}

Please change <version> to the version displayed at the top of this document.

Traditional Method

Apply plugin in your project's build.gradle.kts.

plugins {
    // ...
    id("com.highcapable.hikage") version "<version>"
}

Please change <version> to the version displayed at the top of this document.

Function Introduction

The plugin automatically completes the following work.

  • Applies the Google KSPopen in new window plugin
  • Adds the matching hikage-compiler dependency of the current version to the ksp configuration
  • Reads JSON declaration files under resources/hikage-view-declaration from the current Android main source set and passes them to the compiler as strict declarations
  • Reads JSON declaration files packaged by hikage-declaration-gradle-plugin under META-INF/hikage/view-declaration/<group>/<module>/ from runtime dependencies and passes them to the compiler as optional declarations
  • Generates Hikage performer symbol information for Lint, and excludes META-INF/hikage/** and hikage-view-declaration/** from the final APK / AAB

Tips

If you are a custom view developer, Hikage provides a hikage-declaration-gradle-plugin to handle the view declaration files of third-party dependency libraries, you can use this plugin to automatically package your defined view declaration files, so that users can automatically generate layout component functions (Hikage Performer).

Local View Declaration Files

You can place view declaration files in the main source set resources directory of an Android module, these files are only used to generate layout component functions (Hikage Performer) for the current module and will not be packaged into the final APK / AAB.

src/
└── main
    └── resources
        └── hikage-view-declaration
            ├── foo.json
            ├── bar.json
            └── ...

For the JSON format of the view declaration file, please refer to hikage-compiler → View Declaration File.

External View Declaration Files

When your project depends on modules carrying view declaration files, the plugin automatically collects declaration files from these dependencies.

The following example

dependencies {
    implementation("com.foo:some-widget:<version>")
}

Plugin Configuration

A complete example of plugin configurations is as follows.

The following example

hikage {
    compiler {
        enabled = true
        version = "<version>"
        viewDeclarationFiles = true
        useEmbeddedKsp = true
    }
}
Parameter NameDescription
enabledWhether to enable Hikage compiler wiring, enabled by default
versionThe hikage-compiler's version, aligned with the plugin version by default
viewDeclarationFilesWhether to generate code through View declaration files, enabled by default
useEmbeddedKspWhether to apply the embedded KSP plugin automatically when the current project does not apply KSP, enabled by default

Advanced Usage

If your project needs to control Kotlin and KSP versions by itself, declare the KSP plugin in the root project or current module, and disable the embedded KSP fallback.

The following example

plugins {
    id("com.google.devtools.ksp") version "<ksp-version>" apply false
}
plugins {
    // ...
    id("com.google.devtools.ksp")
    id("com.highcapable.hikage")
}

hikage {
    compiler {
        useEmbeddedKsp = false
    }
}

Notice

This plugin only supports Android projects, your project must include the complete Android Gradle plugin.

If you want to take over KSP and compiler dependencies manually, please refer to the manual configuration method of hikage-compiler.