Update to Gradle 7 (#1078)

This commit is contained in:
Matt 2021-05-14 17:42:37 -04:00 committed by GitHub
parent 9aa25ce109
commit aa0ad16a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 113 additions and 42 deletions

View File

@ -6,7 +6,6 @@ plugins {
} }
repositories { repositories {
jcenter()
gradlePluginPortal() gradlePluginPortal()
maven { maven {
name = "EngineHub" name = "EngineHub"
@ -23,5 +22,5 @@ val properties = Properties().also { props ->
dependencies { dependencies {
implementation(gradleApi()) implementation(gradleApi())
implementation("org.ajoberstar.grgit:grgit-gradle:4.1.0") implementation("org.ajoberstar.grgit:grgit-gradle:4.1.0")
implementation("com.github.jengelman.gradle.plugins:shadow:6.1.0") implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0")
} }

View File

@ -1,6 +1,7 @@
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JvmVendorSpec
import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.repositories import org.gradle.kotlin.dsl.repositories
@ -50,7 +51,8 @@ fun Project.applyCommonConfiguration() {
plugins.withId("java") { plugins.withId("java") {
the<JavaPluginExtension>().toolchain { the<JavaPluginExtension>().toolchain {
languageVersion.set(JavaLanguageVersion.of(8)) languageVersion.set(JavaLanguageVersion.of(11))
vendor.set(JvmVendorSpec.ADOPTOPENJDK)
} }
} }

View File

@ -1,16 +1,27 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.internal.HasConvention import org.gradle.api.attributes.Bundling
import org.gradle.api.plugins.MavenRepositoryHandlerConvention import org.gradle.api.attributes.Category
import org.gradle.api.tasks.Upload import org.gradle.api.attributes.DocsType
import org.gradle.api.attributes.LibraryElements
import org.gradle.api.attributes.Usage
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.component.AdhocComponentWithVariants
import org.gradle.api.component.SoftwareComponentFactory
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getPlugin import org.gradle.kotlin.dsl.getPlugin
import org.gradle.kotlin.dsl.invoke import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.register
import javax.inject.Inject
fun Project.applyLibrariesConfiguration() { fun Project.applyLibrariesConfiguration() {
applyCommonConfiguration() applyCommonConfiguration()
@ -20,14 +31,13 @@ fun Project.applyLibrariesConfiguration() {
configurations { configurations {
create("shade") create("shade")
getByName("archives").extendsFrom(getByName("default"))
} }
group = "${rootProject.group}.worldedit-libs" group = "${rootProject.group}.worldedit-libs"
val relocations = mapOf( val relocations = mapOf(
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text", "net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori" "net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori",
) )
tasks.register<ShadowJar>("jar") { tasks.register<ShadowJar>("jar") {
@ -85,25 +95,85 @@ fun Project.applyLibrariesConfiguration() {
dependsOn("jar", "sourcesJar") dependsOn("jar", "sourcesJar")
} }
artifacts { project.apply<LibsConfigPluginHack>()
val jar = tasks.named("jar")
add("default", jar) { val libsComponent = project.components["libs"] as AdhocComponentWithVariants
builtBy(jar)
val apiElements = project.configurations.register("apiElements") {
isVisible = false
description = "API elements for libs"
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_API))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)
}
outgoing.artifact(tasks.named("jar"))
}
val runtimeElements = project.configurations.register("runtimeElements") {
isVisible = false
description = "Runtime elements for libs"
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)
}
outgoing.artifact(tasks.named("jar"))
}
val sourcesElements = project.configurations.register("sourcesElements") {
isVisible = false
description = "Source elements for libs"
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.DOCUMENTATION))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named(DocsType.SOURCES))
}
outgoing.artifact(tasks.named("sourcesJar"))
}
libsComponent.addVariantsFromConfiguration(apiElements.get()) {
mapToMavenScope("compile")
}
libsComponent.addVariantsFromConfiguration(runtimeElements.get()) {
mapToMavenScope("runtime")
}
libsComponent.addVariantsFromConfiguration(sourcesElements.get()) {
mapToMavenScope("runtime")
}
configure<PublishingExtension> {
publications {
register<MavenPublication>("maven") {
from(libsComponent)
} }
val sourcesJar = tasks.named("sourcesJar")
add("archives", sourcesJar) {
builtBy(sourcesJar)
} }
} }
tasks.register<Upload>("install") { }
configuration = configurations["archives"]
(repositories as HasConvention).convention.getPlugin<MavenRepositoryHandlerConvention>().mavenInstaller {
pom.version = project.version.toString()
pom.artifactId = project.name
}
}
// A horrible hack because `softwareComponentFactory` has to be gotten via plugin
// gradle why
internal open class LibsConfigPluginHack @Inject constructor(
private val softwareComponentFactory: SoftwareComponentFactory
) : Plugin<Project> {
override fun apply(project: Project) {
val libsComponents = softwareComponentFactory.adhoc("libs")
project.components.add(libsComponents)
}
} }
fun Project.constrainDependenciesToLibsCore() { fun Project.constrainDependenciesToLibsCore() {

View File

@ -60,7 +60,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
"testImplementation"("org.mockito:mockito-core:${Versions.MOCKITO}") "testImplementation"("org.mockito:mockito-core:${Versions.MOCKITO}")
"testImplementation"("org.mockito:mockito-junit-jupiter:${Versions.MOCKITO}") "testImplementation"("org.mockito:mockito-junit-jupiter:${Versions.MOCKITO}")
"testImplementation"("net.bytebuddy:byte-buddy:1.11.0") "testImplementation"("net.bytebuddy:byte-buddy:1.11.0")
"testRuntime"("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}") "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}")
} }
// Java 8 turns on doclint which we fail // Java 8 turns on doclint which we fail

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -61,7 +61,7 @@ dependencies {
compileOnly("com.github.MilkBowl:VaultAPI:1.7") { isTransitive = false } compileOnly("com.github.MilkBowl:VaultAPI:1.7") { isTransitive = false }
api(project(":worldedit-core")) api(project(":worldedit-core"))
api(project(":worldedit-libs:bukkit")) api(project(":worldedit-libs:bukkit"))
compile(":worldedit-adapters:") implementation(":worldedit-adapters:")
// Paper-patched NMS jars // Paper-patched NMS jars
compileOnly("com.destroystokyo.paperv1_15_r1:paperv1_15_r1:1_15_r1") compileOnly("com.destroystokyo.paperv1_15_r1:paperv1_15_r1:1_15_r1")
compileOnly("com.destroystokyo.paperv1_16_r1:paperv1_16_r1:1_16_r1") compileOnly("com.destroystokyo.paperv1_16_r1:paperv1_16_r1:1_16_r1")

View File

@ -1,14 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") version "1.4.21" kotlin("jvm") version "1.5.0-RC"
application application
} }
applyCommonConfiguration() applyCommonConfiguration()
tasks.withType<KotlinCompile> { tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8" kotlinOptions.jvmTarget = "11"
} }
application.mainClass.set("com.sk89q.worldedit.internal.util.DocumentationPrinter") application.mainClass.set("com.sk89q.worldedit.internal.util.DocumentationPrinter")