From f7d5a0a01723a6dd86473c26e46cf54ece39b0f5 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:12:45 -0700 Subject: [PATCH] [ci skip] Add remote build cache configuration through Gradle properties (#12797) --- .github/workflows/build.yml | 6 ++++++ build.gradle.kts | 10 +++++----- paper-api/build.gradle.kts | 2 +- settings.gradle.kts | 26 ++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 93f97705f69..8a94b43d34e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,12 @@ on: jobs: build: + env: + ORG_GRADLE_PROJECT_paperBuildCacheEnabled: true + ORG_GRADLE_PROJECT_paperBuildCacheUsername: ${{ secrets.PAPER_BUILD_CACHE_USERNAME }} + ORG_GRADLE_PROJECT_paperBuildCachePassword: ${{ secrets.PAPER_BUILD_CACHE_PASSWORD }} + ORG_GRADLE_PROJECT_paperBuildCachePush: true + # The goal of the build workflow is split into multiple requirements. # 1. Run on pushes to same repo. # 2. Run on PR open/reopen/syncs from repos that are not the same (PRs from the same repo are covered by 1) diff --git a/build.gradle.kts b/build.gradle.kts index dce699b6b27..a732f7ed3ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { - id("io.papermc.paperweight.core") version "2.0.0-beta.17" apply false + id("io.papermc.paperweight.core") version "2.0.0-beta.18" apply false } subprojects { @@ -24,19 +24,19 @@ subprojects { val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/" subprojects { - tasks.withType { + tasks.withType().configureEach { options.encoding = Charsets.UTF_8.name() options.release = 21 options.isFork = true options.compilerArgs.addAll(listOf("-Xlint:-deprecation", "-Xlint:-removal")) } - tasks.withType { + tasks.withType().configureEach { options.encoding = Charsets.UTF_8.name() } - tasks.withType { + tasks.withType().configureEach { filteringCharset = Charsets.UTF_8.name() } - tasks.withType { + tasks.withType().configureEach { testLogging { showStackTraces = true exceptionFormat = TestExceptionFormat.FULL diff --git a/paper-api/build.gradle.kts b/paper-api/build.gradle.kts index db243429f26..f26cad3f5b8 100644 --- a/paper-api/build.gradle.kts +++ b/paper-api/build.gradle.kts @@ -164,7 +164,7 @@ abstract class Services { } val services = objects.newInstance() -tasks.withType { +tasks.withType().configureEach { val options = options as StandardJavadocDocletOptions options.overview = "src/main/javadoc/overview.html" options.use() diff --git a/settings.gradle.kts b/settings.gradle.kts index db2867ddc6a..9289c95a730 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,3 @@ -import java.util.Locale - pluginManagement { repositories { gradlePluginPortal() @@ -56,3 +54,27 @@ fun optionalInclude(name: String, op: (ProjectDescriptor.() -> Unit)? = null) { ) } } + +if (providers.gradleProperty("paperBuildCacheEnabled").orNull.toBoolean()) { + val buildCacheUsername = providers.gradleProperty("paperBuildCacheUsername").orElse("").get() + val buildCachePassword = providers.gradleProperty("paperBuildCachePassword").orElse("").get() + if (buildCacheUsername.isBlank() || buildCachePassword.isBlank()) { + println("The Paper remote build cache is enabled, but no credentials were provided. Remote build cache will not be used.") + } else { + val buildCacheUrl = providers.gradleProperty("paperBuildCacheUrl") + .orElse("https://gradle-build-cache.papermc.io/") + .get() + val buildCachePush = providers.gradleProperty("paperBuildCachePush").orNull?.toBoolean() + ?: System.getProperty("CI").toBoolean() + buildCache { + remote { + url = uri(buildCacheUrl) + isPush = buildCachePush + credentials { + username = buildCacheUsername + password = buildCachePassword + } + } + } + } +}