Skip to content

Commit

Permalink
Build cleanup (#2482)
Browse files Browse the repository at this point in the history
* chore(build): bump gradle plugins, add junit launcher to resolve some deprecations

* chore(build): Move to using version catalogs for dependencies

* chore(build): remove duplicated repository declaration

* chore(build): Clean up idea-ext blocks

* chore(deps): Bump misc dependencies

* chore(build): Silence some warnings from Adventure references

* chore(build): Resolve remaining deprecation warnings

* chore(build): break out idea-ext version for impl use

* chore(build): Bump foojay plugin version

* chore(build): Declare our Java target in one central place
  • Loading branch information
zml2008 authored Jan 27, 2024
1 parent ac8aa2b commit 92619ec
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 99 deletions.
136 changes: 63 additions & 73 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,80 +1,73 @@
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.gradle.ext.delegateActions
import org.jetbrains.gradle.ext.settings
import org.jetbrains.gradle.ext.taskTriggers

buildscript {
dependencies {
classpath("fr.inria.gforge.spoon:spoon-core:10.2.0") // bump for EIG
classpath(libs.spoon) // bump for EIG
}
}

plugins {
eclipse
id("org.spongepowered.gradle.sponge.dev")
id("net.kyori.indra.checkstyle")
id("net.kyori.indra.crossdoc")
id("net.kyori.indra.publishing")
id("net.kyori.indra.publishing.sonatype")
id("org.spongepowered.gradle.event-impl-gen")
id("org.jetbrains.gradle.plugin.idea-ext")
id("net.ltgt.errorprone")
}

repositories {
maven("https://repo.spongepowered.org/repository/maven-public/") {
name = "sponge"
}
alias(libs.plugins.spongeGradle.convention)
alias(libs.plugins.indra.checkstyle)
alias(libs.plugins.indra.crossdoc)
alias(libs.plugins.indra.publishing)
alias(libs.plugins.indra.publishing.sonatype)
alias(libs.plugins.eventImplGen)
alias(libs.plugins.ideaExt)
alias(libs.plugins.errorprone)
alias(libs.plugins.nexusPublish)
}

val javaTarget: String by project
val ap by sourceSets.registering {
compileClasspath += sourceSets.main.get().compileClasspath + sourceSets.main.get().output
}

configurations {
sequenceOf(apiElements, runtimeElements).forEach {
it.configure {
exclude(group = "org.jetbrains", module = "annotations")
}
}
}

// Project dependencies
val adventureVersion: String by project
val configurateVersion: String by project
val gsonVersion: String by project
val log4jVersion: String by project
val mathVersion: String by project
dependencies {
val caffeineVersion: String by project
val errorproneVersion: String by project
val junitVersion: String by project
val mockitoVersion: String by project
val pluginSpiVersion: String by project
val checkerVersion: String by project

// Directly tied to what's available from Minecraft
api("org.apache.logging.log4j:log4j-api:$log4jVersion")
api("com.google.code.gson:gson:$gsonVersion")
api(libs.log4j.api)
api(libs.gson)

// Adventure
api(platform("net.kyori:adventure-bom:$adventureVersion"))
api("net.kyori:adventure-api") {
exclude(group = "org.jetbrains", module = "annotations")
}
api("net.kyori:adventure-text-serializer-gson") {
api(platform(libs.adventure.bom))
api(libs.adventure.api)
api(libs.adventure.textSerializer.gson) {
exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "net.kyori", module = "adventure-api")
}
api("net.kyori:adventure-text-serializer-legacy") {
api(libs.adventure.textSerializer.legacy) {
exclude(group = "net.kyori", module = "adventure-api")
}
api("net.kyori:adventure-text-serializer-plain") {
api(libs.adventure.textSerializer.plain) {
exclude(group = "net.kyori", module = "adventure-api")
}
api("net.kyori:adventure-text-minimessage") {
api(libs.adventure.minimessage) {
exclude(group = "net.kyori", module = "adventure-api")
}

// Dependency injection
api("com.google.inject:guice:5.0.1") {
api(libs.guice) {
exclude(group = "com.google.code.findbugs", module = "jsr305") // We don't want to use jsr305, use checkerframework
exclude(group = "javax.inject", module = "javax.inject")
exclude(group = "com.google.guava", module = "guava") // We use an older version than Guice does
exclude(group = "org.ow2.asm", module = "asm")
}

// High performance cache + guava - shaded guava
api("com.github.ben-manes.caffeine:caffeine:$caffeineVersion") {
api(libs.caffeine) {
exclude(group = "org.checkerframework", module = "checker-qual")
exclude(group = "com.google.errorprone", module = "error_prone_annotations")
exclude(group = "org.junit", module = "junit-bom")
Expand All @@ -84,58 +77,59 @@ dependencies {
}

// Plugin spi, includes plugin-meta
api("org.spongepowered:plugin-spi:$pluginSpiVersion") {
api(libs.pluginSpi) {
exclude(group = "org.checkerframework", module = "checker-qual")
exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
}

// Configurate
api(platform("org.spongepowered:configurate-bom:$configurateVersion"))
api("org.spongepowered:configurate-core") {
api(platform(libs.configurate.bom))
api(libs.configurate.core) {
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
api("org.spongepowered:configurate-hocon") {
api(libs.configurate.hocon) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")

}
api("org.spongepowered:configurate-gson") {
api(libs.configurate.gson) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "com.google.code.gson", module = "gson") // We have the same version technically, but use the gson we provide.
exclude(group = "org.checkerframework", module = "checker-qual")
}
api("org.spongepowered:configurate-yaml") {
api(libs.configurate.yaml) {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")
}
api("org.spongepowered:configurate-extra-guice") {
api(libs.configurate.extraGuice) {
exclude(group = "com.google.inject", module = "guice")
}

// Compile-time static analysis
compileOnly("com.google.errorprone:error_prone_annotations:$errorproneVersion")
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
compileOnly(libs.errorprone.annotations)
errorprone(libs.errorprone)

// Math library
api("org.spongepowered:math:$mathVersion") {
api(libs.math) {
exclude(group = "com.google.errorprone", module = "error_prone_annotations")
}

compileOnlyApi("org.checkerframework:checker-qual:$checkerVersion")
compileOnlyApi(libs.checkerQual)

testImplementation(platform("org.junit:junit-bom:$junitVersion"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.mockito:mockito-core:$mockitoVersion")
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.api)
testImplementation(libs.junit.params)
testRuntimeOnly(libs.junit.engine)
testRuntimeOnly(libs.junit.launcher)
testImplementation(libs.hamcrest)
testImplementation(libs.mockito)
}

tasks {
genEventImpl {
sourceCompatibility = "16"
destinationDir = project.layout.buildDirectory.dir("generated/event-factory").get().asFile
sourceCompatibility = javaTarget
destinationDirectory = project.layout.buildDirectory.dir("generated/event-factory")

outputFactory = "org.spongepowered.api.event.SpongeEventFactory"
include("org/spongepowered/api/event/*/**/*")
Expand Down Expand Up @@ -180,14 +174,14 @@ tasks {
options {
(this as? StandardJavadocDocletOptions)?.apply {
links(
"https://logging.apache.org/log4j/log4j-$log4jVersion/log4j-api/apidocs/",
"https://google.github.io/guice/api-docs/5.0.1/javadoc/",
"https://configurate.aoeu.xyz/$configurateVersion/apidocs/",
"https://www.javadoc.io/doc/com.google.code.gson/gson/$gsonVersion/",
"https://jd.spongepowered.org/math/$mathVersion"
"https://logging.apache.org/log4j/log4j-${libs.versions.log4j.get()}/log4j-api/apidocs/",
"https://google.github.io/guice/api-docs/${libs.versions.guice.get()}/javadoc/",
"https://configurate.aoeu.xyz/${libs.versions.configurate.get()}/apidocs/",
"https://www.javadoc.io/doc/com.google.code.gson/gson/${libs.versions.gson.get()}/",
"https://jd.spongepowered.org/math/${libs.versions.math.get()}"
)
sequenceOf("api", "key", "text-serializer-gson", "text-serializer-legacy", "text-serializer-plain").forEach {
links("https://jd.advntr.dev/$it/$adventureVersion/")
links("https://jd.advntr.dev/$it/${libs.versions.adventure.get()}/")
}
addBooleanOption("quiet", true)
}
Expand All @@ -212,14 +206,12 @@ tasks {

idea {
if (project != null) {
(project as ExtensionAware).extensions["settings"].run {
require(this is ExtensionAware)

this.extensions.getByType(org.jetbrains.gradle.ext.ActionDelegationConfig::class).run {
project.settings.run {
delegateActions {
delegateBuildRunToGradle = false
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
}
this.extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
taskTriggers {
beforeBuild(tasks.genEventImpl)
}
}
Expand Down Expand Up @@ -249,12 +241,10 @@ spongeConvention {
}

indra {
val checkstyleVersion: String by project

javaVersions {
target(17)
target(javaTarget.toInt())
}
checkstyle(checkstyleVersion)
checkstyle(libs.versions.checkstyle.get())

configurePublications {
artifactId = project.name.lowercase()
Expand Down
15 changes: 1 addition & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,8 @@ version=11.0.0-SNAPSHOT
organization=SpongePowered
projectUrl=https://www.spongepowered.org
projectDescription=A plugin API for Minecraft: Java Edition
javaTarget=17

javadocPublishRoot=https://jd.spongepowered.org/

org.gradle.parallel=true

adventureVersion=4.12.0
caffeineVersion=3.1.8
checkstyleVersion=10.12.4
configurateVersion=4.1.2
errorproneVersion=2.23.0
gsonVersion=2.10.1
junitVersion=5.9.1
log4jVersion=2.19.0

mathVersion=2.0.1
mockitoVersion=4.8.0
pluginSpiVersion=0.3.0
checkerVersion=3.26.0
67 changes: 67 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[metadata]
format = { version = "1.1" }

[versions]
adventure = "4.12.0"
caffeine = "3.1.8"
checker = "3.42.0"
checkstyle = "10.12.7"
configurate = "4.1.2"
errorprone = "2.24.1"
gson = "2.10.1"
guice = "5.0.1"
ideaExt = "1.1.7"
indra = "3.1.3"
junit = "5.10.1"
log4j = "2.19.0"
math = "2.0.1"
mockito = "5.9.0"
pluginSpi = "0.3.0"

[libraries]
adventure-bom = { module = "net.kyori:adventure-bom", version.ref = "adventure" }
adventure-api = { module = "net.kyori:adventure-api" }
adventure-textSerializer-gson = { module = "net.kyori:adventure-text-serializer-gson" }
adventure-textSerializer-legacy = { module = "net.kyori:adventure-text-serializer-legacy" }
adventure-textSerializer-plain = { module = "net.kyori:adventure-text-serializer-plain" }
adventure-minimessage = { module = "net.kyori:adventure-text-minimessage" }
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" }
configurate-bom = { module = "org.spongepowered:configurate-bom", version.ref = "configurate" }
configurate-core = { module = "org.spongepowered:configurate-core" }
configurate-hocon = { module = "org.spongepowered:configurate-hocon" }
configurate-gson = { module = "org.spongepowered:configurate-gson" }
configurate-yaml = { module = "org.spongepowered:configurate-yaml" }
configurate-extraGuice = { module = "org.spongepowered:configurate-extra-guice" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
guice = { module = "com.google.inject:guice", version.ref = "guice" }
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
math = { module = "org.spongepowered:math", version.ref = "math" }
pluginSpi = { module = "org.spongepowered:plugin-spi", version.ref = "pluginSpi" }

# build-time/annotations

checkerQual = { module = "org.checkerframework:checker-qual", version.ref = "checker" }
errorprone = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone" }
errorprone-annotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "errorprone" }
spoon = { module = "fr.inria.gforge.spoon:spoon-core", version = "10.4.2" } # bump for EIG

# testing

hamcrest = { module = "org.hamcrest:hamcrest", version = "2.2" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-params = { module = "org.junit.jupiter:junit-jupiter-params" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
junit-launcher = { module = "org.junit.platform:junit-platform-launcher" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }

[plugins]
errorprone = { id = "net.ltgt.errorprone", version = "3.1.0" }
eventImplGen = { id = "org.spongepowered.gradle.event-impl-gen", version = "7.1.0" }
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaExt" }
indra-checkstyle = { id = "net.kyori.indra.checkstyle", version.ref = "indra" }
indra-crossdoc = { id = "net.kyori.indra.crossdoc", version.ref = "indra" }
indra-publishing = { id = "net.kyori.indra.publishing", version.ref = "indra" }
indra-publishing-sonatype = { id = "net.kyori.indra.publishing.sonatype", version.ref = "indra" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0-rc-1"}
spongeGradle-convention = { id = "org.spongepowered.gradle.sponge.dev", version = "2.2.0" }
19 changes: 7 additions & 12 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ pluginManagement {
name = "sponge"
}
}
plugins {
val indraVersion = "3.1.3"
id("org.spongepowered.gradle.event-impl-gen") version "7.0.0"
id("org.spongepowered.gradle.sponge.dev") version "2.1.1"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
id("net.ltgt.errorprone") version "3.1.0"
id("net.kyori.indra.publishing") version indraVersion
id("net.kyori.indra.publishing.sonatype") version indraVersion
id("net.kyori.indra.checkstyle") version indraVersion
id("net.kyori.indra.crossdoc") version indraVersion
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.7.0")
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0")
}

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
pluginManagement.repositories.forEach(repositories::add)
}

0 comments on commit 92619ec

Please sign in to comment.