From 13a19001d97212935cabed8365326f72129b82d9 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Fri, 7 Jun 2024 00:25:56 -0500 Subject: [PATCH] add docs --- README.md | 91 +++++++++++++++++++ .../expect/ExpectPlatformExtension.kt | 6 +- 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 067abaf..9b59bdb 100644 --- a/README.md +++ b/README.md @@ -1 +1,92 @@ # ExpectPlatform + +This is a simple project that implements `@ExpectPlatform` and `@PlatformOnly` in a non-specific way. + +## Usage + +to use this project, you can add the following to your `settings.gradle` file: +```gradle +pluginManagement { + repositories { + mavenLocal() + maven { + url = "https://maven.wagyourtail.xyz/releases" + } + maven { + url = "https://maven.wagyourtail.xyz/snapshots" + } + mavenCentral() + gradlePluginPortal() + } +} +``` + +and then add the plugin to your `build.gradle` file: +```gradle +plugins { + id 'xyz.wagyourtail.unimined.expect-platform' version '1.0.3' +} +``` + +you can add the annotations to be accessible with +```gradle +dependencies { + implementation(expectPlatform.annotationsDep) + // or + implementation("xyz.wagyourtail.unimined:expect-platform-annotations:${expectPlatform.version}") +} +``` + +to then apply the annotations in a subproject or other module, you can either do: + +```gradle +tasks.create("expectPlatformOutput") { + group = "unimined" + platformName = platformName + inputCollection = rootProject.sourceSets["main"].output +} + +dependencies { + common(expectPlatformOutput.outputCollection) +} +``` + +or, you can apply the agent to a JavaExec and create a task to make the final jar: + +```gradle +tasks.withType(JavaExec) { + expectPlatform.insertAgent(it, platformName) +} + +tasks.create("PlatformJar", xyz.wagyourtail.unimined.expect.ExpectPlatformJar) { + group = "unimined" + dependsOn("jar") + + inputFiles = tasks.jar.outputs.files + platformName = platformName +} + +``` + +if you need the agent on a runner that isn't implementing JavaExecSpec (ie, the one in unimined) +check [the implementation](src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt#L69) for how it actually applies the agent to a JavaExec task. + +### Environment + +This plugin also provides an `@Environment` annotation, but doesn't hook it up. +to do so, you can use the following code snippets (as either setting in the task, or the third arg to the agent): +```gradle +// neoforge + remap = [ + "xyz/wagyourtail/unimined/expect/annotation/Environment": "net/neoforged/api/distmarker/OnlyIn", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "net/neoforged/api/distmarker/Dist", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.SERVER": "DEDICATED_SERVER", + ] +// fabric + remap = [ + "xyz/wagyourtail/unimined/expect/annotation/Environment": "net/fabricmc/api/Environment", + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "net/fabricmc/api/EnvType", + ] +``` + +Do note that while this plugin contains `EnvType.COMBINED`, it is not present in fabric or neoforge, so it is not recommended to use it. \ No newline at end of file diff --git a/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt b/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt index 1f56edd..2f72f02 100644 --- a/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt +++ b/src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt @@ -5,14 +5,14 @@ import groovy.lang.DelegatesTo import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.attributes.Attribute -import org.gradle.api.tasks.Internal import org.gradle.process.JavaExecSpec +import org.jetbrains.annotations.VisibleForTesting import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformParams import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformTransform abstract class ExpectPlatformExtension(val project: Project) { - @get:Internal - @set:Internal + + @set:VisibleForTesting var version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0.0-SNAPSHOT" val annotationsDep by lazy { "xyz.wagyourtail.unimined.expect-platform:expect-platform-annotations:$version" }