Skip to content

Commit fa0a738

Browse files
committed
Multi-project example
1 parent fb5dbb7 commit fa0a738

File tree

17 files changed

+240
-55
lines changed

17 files changed

+240
-55
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ jobs:
2222
distribution: 'temurin'
2323
- name: Setup Gradle
2424
uses: gradle/actions/setup-gradle@v5
25+
with:
26+
cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/multi-project' }}
2527
- name: Build
2628
run: ./gradlew build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ buildNumber.properties
117117

118118
# Common working directory
119119
run/
120+
run1_19_4/
121+
run1_17_1/
120122
build
121123
.gradle
122124
/*.jar

build.gradle.kts

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,72 @@
11
import xyz.jpenilla.resourcefactory.bukkit.BukkitPluginYaml
2+
import xyz.jpenilla.runpaper.task.RunServer
23

34
plugins {
4-
`java-library`
5-
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
6-
id("xyz.jpenilla.run-paper") version "3.0.2" // Adds runServer and runMojangMappedServer tasks for testing
5+
`my-conventions`
6+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19" apply false
7+
id("xyz.jpenilla.run-paper") version "3.0.2" // Adds runServer task for testing
78
id("xyz.jpenilla.resource-factory-bukkit-convention") version "1.3.0" // Generates plugin.yml based on the Gradle config
9+
id("com.gradleup.shadow") version "9.2.2"
810
}
911

10-
group = "io.papermc.paperweight"
11-
version = "1.0.0-SNAPSHOT"
12-
description = "Test plugin for paperweight-userdev"
12+
java.disableAutoTargetJvm() // Allow consuming JVM 21 projects (i.e. paper_1_21_8) even though our release is 17
1313

14-
java {
15-
// Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 11 installed for example.
16-
toolchain.languageVersion = JavaLanguageVersion.of(21)
17-
}
14+
dependencies {
15+
compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT")
1816

19-
// For 1.20.4 or below, or when you care about supporting Spigot on >=1.20.5:
20-
/*
21-
paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
17+
implementation(project(":paper_hooks"))
2218

23-
tasks.assemble {
24-
dependsOn(tasks.reobfJar)
19+
// Shade the reobf variant
20+
runtimeOnly(project(":paper_1_17_1", configuration = "reobf"))
21+
runtimeOnly(project(":paper_1_19_4", configuration = "reobf"))
22+
23+
// For Paper 1.20.5+, we don't need to use the reobf variant.
24+
// If you still support spigot, you will need to use the reobf variant,
25+
// and remove the Mojang-mapped metadata from the manifest below.
26+
runtimeOnly(project(":paper_1_21_10"))
2527
}
26-
*/
2728

28-
dependencies {
29-
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT")
30-
// paperweight.foliaDevBundle("1.21.10-R0.1-SNAPSHOT")
31-
// paperweight.devBundle("com.example.paperfork", "1.21.10-R0.1-SNAPSHOT")
29+
tasks.assemble {
30+
dependsOn(tasks.shadowJar)
3231
}
3332

34-
tasks {
35-
compileJava {
36-
// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
37-
// See https://openjdk.java.net/jeps/247 for more information.
38-
options.release = 21
39-
}
40-
javadoc {
41-
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
42-
}
33+
tasks.jar {
34+
manifest.attributes(
35+
"paperweight-mappings-namespace" to "mojang",
36+
)
37+
}
4338

44-
// Only relevant for 1.20.4 or below, or when you care about supporting Spigot on >=1.20.5:
45-
/*
46-
reobfJar {
47-
// This is an example of how you might change the output location for reobfJar. It's recommended not to do this
48-
// for a variety of reasons, however it's asked frequently enough that an example of how to do it is included here.
49-
outputJar = layout.buildDirectory.file("libs/PaperweightTestPlugin-${project.version}.jar")
39+
tasks.shadowJar {
40+
mergeServiceFiles()
41+
// Needed for mergeServiceFiles to work properly in Shadow 9+
42+
filesMatching("META-INF/services/**") {
43+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
5044
}
51-
*/
5245
}
5346

5447
// Configure plugin.yml generation
5548
// - name, version, and description are inherited from the Gradle project.
5649
bukkitPluginYaml {
57-
main = "io.papermc.paperweight.testplugin.TestPlugin"
50+
main = "my.plugin.MyPlugin"
5851
load = BukkitPluginYaml.PluginLoadOrder.STARTUP
5952
authors.add("Author")
60-
apiVersion = "1.21.10"
53+
apiVersion = "1.17"
54+
}
55+
56+
tasks.runServer {
57+
minecraftVersion("1.21.10")
58+
}
59+
60+
tasks.register("run1_17_1", RunServer::class) {
61+
minecraftVersion("1.17.1")
62+
pluginJars.from(tasks.shadowJar.flatMap { it.archiveFile })
63+
runDirectory = layout.projectDirectory.dir("run1_17_1")
64+
systemProperties["Paper.IgnoreJavaVersion"] = true
65+
}
66+
67+
tasks.register("run1_19_4", RunServer::class) {
68+
minecraftVersion("1.19.4")
69+
pluginJars.from(tasks.shadowJar.flatMap { it.archiveFile })
70+
runDirectory = layout.projectDirectory.dir("run1_19_4")
71+
systemProperties["Paper.IgnoreJavaVersion"] = true
6172
}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import org.gradle.jvm.toolchain.JavaLanguageVersion
2+
import org.gradle.kotlin.dsl.maven
3+
import org.gradle.kotlin.dsl.repositories
4+
5+
plugins {
6+
`java-library`
7+
}
8+
9+
java {
10+
// Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 17 installed for example.
11+
// If you need to compile to for example JVM 8 or 17 bytecode, adjust the 'release' option below and keep the toolchain at 21.
12+
toolchain.languageVersion = JavaLanguageVersion.of(21)
13+
}
14+
15+
repositories {
16+
maven("https://repo.papermc.io/repository/maven-public/")
17+
}
18+
19+
tasks {
20+
withType<JavaCompile>().configureEach {
21+
// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
22+
// See https://openjdk.java.net/jeps/247 for more information.
23+
options.release = 17
24+
}
25+
withType<Javadoc>().configureEach {
26+
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
27+
}
28+
}

gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Project meta
2+
group = io.papermc.paperweight
3+
version = 1.0.0-SNAPSHOT
4+
description = Test plugin for paperweight-userdev
5+
6+
# Gradle configuration
17
org.gradle.parallel=true
28
org.gradle.caching=true
39
org.gradle.configuration-cache=true

paper_1_17_1/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
`my-conventions`
3+
id("io.papermc.paperweight.userdev")
4+
}
5+
6+
dependencies {
7+
implementation(project(":paper_hooks"))
8+
9+
paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT")
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package my.plugin.hooks.paper_1_17_1;
2+
3+
import my.plugin.hooks.PaperHooks;
4+
import net.minecraft.SharedConstants;
5+
import org.slf4j.Logger;
6+
7+
public class PaperHooks1_17_1 implements PaperHooks {
8+
@Override
9+
public void doSomething(final Logger logger) {
10+
logger.info(SharedConstants.getCurrentVersion().getName());
11+
}
12+
}

paper_1_19_4/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
`my-conventions`
3+
id("io.papermc.paperweight.userdev")
4+
}
5+
6+
dependencies {
7+
implementation(project(":paper_hooks"))
8+
9+
paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT")
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package my.plugin.hooks.paper_1_19_4;
2+
3+
import my.plugin.hooks.PaperHooks;
4+
import net.minecraft.SharedConstants;
5+
import org.slf4j.Logger;
6+
7+
public class PaperHooks1_19_4 implements PaperHooks {
8+
@Override
9+
public void doSomething(final Logger logger) {
10+
logger.info(SharedConstants.getCurrentVersion().getName());
11+
}
12+
}

0 commit comments

Comments
 (0)