|
1 | 1 | # ExpectPlatform |
| 2 | + |
| 3 | +This is a simple project that implements `@ExpectPlatform` and `@PlatformOnly` in a non-specific way. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +to use this project, you can add the following to your `settings.gradle` file: |
| 8 | +```gradle |
| 9 | +pluginManagement { |
| 10 | + repositories { |
| 11 | + mavenLocal() |
| 12 | + maven { |
| 13 | + url = "https://maven.wagyourtail.xyz/releases" |
| 14 | + } |
| 15 | + maven { |
| 16 | + url = "https://maven.wagyourtail.xyz/snapshots" |
| 17 | + } |
| 18 | + mavenCentral() |
| 19 | + gradlePluginPortal() |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +and then add the plugin to your `build.gradle` file: |
| 25 | +```gradle |
| 26 | +plugins { |
| 27 | + id 'xyz.wagyourtail.unimined.expect-platform' version '1.0.3' |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +you can add the annotations to be accessible with |
| 32 | +```gradle |
| 33 | +dependencies { |
| 34 | + implementation(expectPlatform.annotationsDep) |
| 35 | + // or |
| 36 | + implementation("xyz.wagyourtail.unimined:expect-platform-annotations:${expectPlatform.version}") |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +to then apply the annotations in a subproject or other module, you can either do: |
| 41 | + |
| 42 | +```gradle |
| 43 | +tasks.create("expectPlatformOutput") { |
| 44 | + group = "unimined" |
| 45 | + platformName = platformName |
| 46 | + inputCollection = rootProject.sourceSets["main"].output |
| 47 | +} |
| 48 | +
|
| 49 | +dependencies { |
| 50 | + common(expectPlatformOutput.outputCollection) |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +or, you can apply the agent to a JavaExec and create a task to make the final jar: |
| 55 | + |
| 56 | +```gradle |
| 57 | +tasks.withType(JavaExec) { |
| 58 | + expectPlatform.insertAgent(it, platformName) |
| 59 | +} |
| 60 | +
|
| 61 | +tasks.create("PlatformJar", xyz.wagyourtail.unimined.expect.ExpectPlatformJar) { |
| 62 | + group = "unimined" |
| 63 | + dependsOn("jar") |
| 64 | + |
| 65 | + inputFiles = tasks.jar.outputs.files |
| 66 | + platformName = platformName |
| 67 | +} |
| 68 | +
|
| 69 | +``` |
| 70 | + |
| 71 | +if you need the agent on a runner that isn't implementing JavaExecSpec (ie, the one in unimined) |
| 72 | +check [the implementation](src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt#L69) for how it actually applies the agent to a JavaExec task. |
| 73 | + |
| 74 | +### Environment |
| 75 | + |
| 76 | +This plugin also provides an `@Environment` annotation, but doesn't hook it up. |
| 77 | +to do so, you can use the following code snippets (as either setting in the task, or the third arg to the agent): |
| 78 | +```gradle |
| 79 | +// neoforge |
| 80 | + remap = [ |
| 81 | + "xyz/wagyourtail/unimined/expect/annotation/Environment": "net/neoforged/api/distmarker/OnlyIn", |
| 82 | + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "net/neoforged/api/distmarker/Dist", |
| 83 | + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.SERVER": "DEDICATED_SERVER", |
| 84 | + ] |
| 85 | +// fabric |
| 86 | + remap = [ |
| 87 | + "xyz/wagyourtail/unimined/expect/annotation/Environment": "net/fabricmc/api/Environment", |
| 88 | + "xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType": "net/fabricmc/api/EnvType", |
| 89 | + ] |
| 90 | +``` |
| 91 | + |
| 92 | +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. |
0 commit comments