Skip to content

Commit

Permalink
Merge pull request #146 from KyoriPowered/feat/j11
Browse files Browse the repository at this point in the history
feat(*): Require a minimum of Java 11 at runtime
  • Loading branch information
zml2008 authored Aug 29, 2023
2 parents 6f337b7 + 06ebd75 commit c265b5e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 80 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ subprojects {
ci true
}
mitLicense()
javaVersions().testWith(11, 17, 20)
javaVersions {
target 11
minimumToolchain 17
testWith(11, 17, 20)
}

signWithKeyFromPrefixedProperties("kyori")
configurePublications {
Expand Down
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gradlePluginPublish = "1.2.1"
immutables = "2.9.3"
indra = "3.1.2"
jetbrainsAnnotations = "24.0.1"
jgit = "5.13.0.+" # stay on 5.x series, 6+ requires Java 11
jgit = "6.6.0.+" # stay on 5.x series, 6+ requires Java 11
junit = "5.10.0"
kotlin = "1.9.10"
mammoth = "1.3.1"
Expand Down Expand Up @@ -48,8 +48,7 @@ gradlePluginPublish = { module = "com.gradle.publish:plugin-publish-plugin", ver
nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version = "1.3.0" }

# spotless-licenser
spotlessLegacy = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.13.0" } # build against this, for J8 support
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" } # published as a dep on a special J11+ variant
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }

# testlib
mammoth-test = { module = "net.kyori:mammoth-test", version.ref = "mammoth" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2020-2022 KyoriPowered
* Copyright (c) 2020-2023 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -62,7 +62,7 @@
public class IndraExtensionImpl implements IndraExtension {

private static final Logger LOGGER = Logging.getLogger(IndraExtensionImpl.class);
private static final String DEFAULT_CHECKSTYLE_VERSION = "9.3";
private static final String DEFAULT_CHECKSTYLE_VERSION = "10.12.3";

private final Property<ContinuousIntegration> ci;
private final Property<Issues> issues;
Expand Down
75 changes: 1 addition & 74 deletions indra-licenser-spotless/build.gradle
Original file line number Diff line number Diff line change
@@ -1,72 +1,12 @@
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.plugins.internal.JavaConfigurationVariantMapping

static def transferAttributes(HasAttributes src, HasAttributes dest) {
def destAttrs = dest.attributes
src.attributes.keySet().each {
destAttrs.attribute(it, src.attributes.getAttribute(it))
}
}

def duplicateConfiguration(Configuration src, String name, Configuration parent) {
configurations.create(name) {
canBeConsumed = true
canBeResolved = false
visible = true

transferAttributes(src, delegate)
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)

outgoing.variants.addAll(src.outgoing.variants)
outgoing.variants.configureEach {
it.attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)
}
artifacts.addAll(src.artifacts)

src.incoming.dependencies.each {
if (it.group != "com.diffplug.spotless") { // yikes
project.dependencies.add(name, it)
}
}
extendsFrom parent
}
}

configurations {
java11Deps {
canBeConsumed = false
canBeResolved = true
}
}

dependencies {
compileOnlyApi libs.jetbrainsAnnotations
api libs.mammoth
api libs.spotlessLegacy
java11Deps libs.spotless
api libs.spotless
testImplementation project(":indra-testlib")
testImplementation libs.spotless
}

configurations {
// must be after dep declaration because we eagerly read declared deps
duplicateConfiguration(apiElements, 'java11ApiElements', java11Deps)
duplicateConfiguration(runtimeElements, 'java11RuntimeElements', java11Deps)

[testCompileClasspath, testRuntimeClasspath].each {
it.attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)
}
}
}

components.java {
// This is technically internal api but because it's our own buildscript we can just update as needed
// and it's easier than matching their logic
addVariantsFromConfiguration(configurations.java11ApiElements, new JavaConfigurationVariantMapping('compile', true))
addVariantsFromConfiguration(configurations.java11RuntimeElements, new JavaConfigurationVariantMapping('runtime', true))
}

indraPluginPublishing {
plugin(
"indra.licenser.spotless",
Expand All @@ -76,16 +16,3 @@ indraPluginPublishing {
["indra", "licenser", "license-header", "spotless"]
)
}

tasks.named('pluginUnderTestMetadata', PluginUnderTestMetadata).configure {
pluginClasspath.setFrom(sourceSets.main.output, configurations.java11Deps, configurations.runtimeClasspath)
}

indra {
javaVersions {
// TODO(4): remove this since we'll target 11
def oldTestWith = testWith().get()
testWith().empty()
testWith().addAll(oldTestWith.findAll { it != 8})
}
}
10 changes: 10 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ dependencyResolutionManagement {

rootProject.name = "indra"

def requiredRuntime = 11
if (JavaVersion.current() < JavaVersion.toVersion(requiredRuntime)) {
throw new GradleException("""\
You are running a Java version that is too old to build Indra.
Required: ${requiredRuntime}
Current: ${JavaVersion.current()}
""".stripIndent())
}

[
"indra-common",
"indra-git",
Expand Down

0 comments on commit c265b5e

Please sign in to comment.