R4J is a utility library that dynamically creates classes for the resources available to a source set. R4J consists of a gradle plugin as well as extension modules to make use of the created classes in java/kotlin. Each resource directory is represented by a nested enum, files by enum values respectively. Every enum implements io.github.peppshabender.r4j.Resource
in order to be picked up by the extension modules.
Note
This is intended for end-level application.. You don't want to expose your resource file structure
In order to apply the plugin, add the gradlePluginPortal()
to your settings.gradle.kts
pluginManagement {
repositories {
gradlePluginPortal()
}
}
and add the relevant dependencies in the build.gradle.kts
plugins {
id("io.github.peppshabender.r4j") version "0.0.1"
}
repositories {
mavenCentral()
}
To make full use of the generated classes, include the necessary dependencies for your project via io.github.peppshabender.r4j.gradle.utils.r4j
. For a Java project, include something like
import io.github.peppshabender.r4j.gradle.utils.r4j
. . .
dependencies {
implementation(r4j.api)
implementation(r4j.java)
}
in your build.gradle.kts
.
R4J can optionally be configured using the r4jConfig {}
extension, the default configuration would look like
r4jConfig {
pkg = "generated.r4j"
className = "Resources"
keepExtension = false
buildJava()
}
pkg
: Sets the package resource holders will be created in (the source set will always be main/SPECIFIC_SOURCE_SET)className
: Adjusts the suffix of the class, the prefix will always be the respective source set namekeepExtension
: If true, file extensions are kept for the constant names, they are omitted otherwise- You can also choose between different builders
buildJava()
can be used to build java enums,buildKotlin()
for kotlin enums respectively- In order to supply your own builder, implement a custom IResourceFileBuilder and supply it via
buildCustom(builder)
R4J provides the r4j
task which can be manually executed to re-create resource holders. For buildJava()
and buildKotlin()
the respective compile task will depend on r4j
automatically.