[docs] Update for compiler plugin v2
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details
ci/woodpecker/tag/docs Pipeline was successful Details
ci/woodpecker/tag/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2022-12-29 13:31:08 +01:00
parent 05de1a67dd
commit ac374ca790
Signed by: Johannes
GPG Key ID: E76429612C2929F4
6 changed files with 28 additions and 41 deletions

View File

@ -4,24 +4,8 @@ Generally, using a combination of its modules is recommended.
On the following pages, the modules of libjf-config are explained in more detail.
If you just want to get started, a quick setup example for a client-side mod using the compiler plugin can be seen below:
settings.gradle:
```groovy
pluginManagement {
repositories {
maven {
name = 'LibJF'
url = 'https://maven.frohnmeyer-wds.de/artifacts'
}
}
}
```
build.gradle:
```groovy
plugins {
id 'io.gitlab.jfronny.libjf.libjf-config-compiler-plugin' version 'VERSION'
}
repositories {
maven { url 'https://maven.frohnmeyer-wds.de/artifacts' }
}
@ -31,19 +15,7 @@ dependencies {
include modRuntimeOnly("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${project.libjf_version}")
include("io.gitlab.jfronny.libjf:libjf-base:${project.libjf_version}")
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-reflect-v1:${project.libjf_version}")
}
task injectCompiledConfig(type: io.gitlab.jfronny.libjf.config.plugin.ConfigInjectTask, dependsOn: jar) {
from jar
modId = archivesBaseName
archiveClassifier = 'config-inject'
destinationDirectory = file("${project.buildDir}/devlibs")
}
remapJar {
dependsOn injectCompiledConfig
input = injectCompiledConfig.archiveFile
annotationProcessor("io.gitlab.jfronny.libjf:libjf-config-compiler-plugin-v2:${project.libjf_version}")
}
loom {
@ -53,13 +25,17 @@ loom {
})
}
}
compileJava {
options.compilerArgs << "-AmodId=" + archivesName // optionally fill in your mod id explicitly
}
```
fabric.mod.json:
```json
{
"entrypoints": {
"libjf:config": ["Your config class here"]
"libjf:config": ["some.package.JFC_YourConfigClass"] // The JFC_ prefix is for the config-compiler-plugin-v2-generated classes
}
}
```
@ -69,6 +45,10 @@ Config class:
@JfConfig
public class ConfigExample {
@Entry public static boolean someEntry = true;
static {
JFC_ConfigExample.ensureInitialized();
}
}
```

View File

@ -0,0 +1,11 @@
# libjf-config-compiler-plugin-v2
This annotation processor provides finds classes annotated with `@JfConfig` and produces the necessary code and registration for them.
Using this is the recommended way to use libjf-config.
Please be aware that the restrictions of [the reflection implementation](./libjf-config-reflect-v1.md) in regard to class loading
will also apply to configs using the plugin if it is loaded during runtime.
Please note that your `fabric.mod.json` must reference the generated class, not your original config.
If you plan on accessing your config before `onInitialize`, it is recommended that you call `.ensureInitialized()` on your
generated class from your config classes static initializer as seen in the example.
The code necessary for using this annotation processor is available [here](./)

View File

@ -1,9 +0,0 @@
# libjf-config-compiler-plugin
This gradle plugin provides a task that identifies any config files in a jar and produces the necessary code and registration for it.
Using this is the recommended way to use libjf-config.
Please be aware that the restrictions of [the reflection implementation](./libjf-config-reflect-v1.md) in regard to class loading
will also apply to configs using the plugin if it is loaded during runtime.
Using the reflection implementation as `modRuntimeLocal` is also recommended since the compiler plugin will be unable to affect loom dev envs otherwise.
The code necessary for using this plugin is available [here](./)

View File

@ -4,5 +4,5 @@ In order to register a config, simply add the class annotated as `@JfConfig` to
Please be aware that this module may load your config class before the game classes are available.
Using them there WILL result in problems!
You should use this module in dev when relying on the [compiler plugin](./libjf-config-compiler-plugin.md) for prod,
as it is not applied in your dev env, and you will be unable to change configs without it.
Instead of using this implementation, you should use the [compiler plugin](./libjf-config-compiler-plugin-v2.md),
which removes the runtime overhead of this implementation.

View File

@ -131,6 +131,7 @@ public class ConfigProcessor extends AbstractProcessor2 {
spec.addMethod(MethodSpec.methodBuilder("write").addModifiers(Modifier.PUBLIC, Modifier.STATIC).addCode("INSTANCE.write();").build());
spec.addMethod(MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC).addCode("INSTANCE.load();").build());
spec.addMethod(MethodSpec.methodBuilder("register").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(DSL.Defaulted.class, "dsl").build());
spec.addMethod(MethodSpec.methodBuilder("ensureInitialized").addModifiers(Modifier.STATIC).build());
}
private void process(TypeElement source, CodeBlock.Builder code, AtomicInteger i) {

View File

@ -24,4 +24,8 @@ public class JfWebConfig {
ConfigHolder.getInstance().getRegistered().get("libjf-web-v0").write();
}
}
static {
JFC_JfWebConfig.ensureInitialized();
}
}