mirror of
https://github.com/fankes/moshi.git
synced 2025-10-18 23:49:21 +08:00
Implement reflective support for Java Records (#1381)
* Standardize around JDK 8 * Update GJF to support newer JDKs * Fix misc java 8 issues in tests * Prepare java 16/records checking at runtime * Implement real RecordJsonAdapter * Spotless * Prepare build for JDK 16+ * Fix property name for kapt * Small cleanup * Make FallbackEnum java-8 happy * Remove animalsniffer * Fix format * Add opens for ExtendsPlatformClassWithProtectedFields * Return null every time in shim for main tests * Use JDK 16 + release 8 to replace animalsniffer * Simplify accessor accessible handling * Remove manifest attrs * Fix typo * Fix KCT tests + upgrade it * Cover another * Try explicit kotlin daemon args for java 17? * Disable 17-ea for now until kotlin 1.5.30 * Add JsonQualifier and Json(name) tests + fix qualifiers * Ensure constructor is accessible * GJF it properly * GJF 1.11 * Unwrap InvocationTargetException * Use MethodHandle for constructor * Use MethodHandle for accessor too * Revert "Remove manifest attrs" This reverts commit 3eb768fd6904bb5c979aa01c3c182e0fb9329d62. * Proper MR jar * *actually* fix GJF, which wasn't getting applied before We can just enable this everywhere now since we require JDK 16 anyway * Make IDE happy about modules access * Fixup records tests to play nice with modules Gotta be public * Add complex smoke test * Remove comment Not a regression test in this case
This commit is contained in:
100
build.gradle.kts
100
build.gradle.kts
@@ -33,7 +33,6 @@ plugins {
|
||||
id("com.vanniktech.maven.publish") version "0.14.2" apply false
|
||||
id("org.jetbrains.dokka") version "1.4.32" apply false
|
||||
id("com.diffplug.spotless") version "5.12.4"
|
||||
id("ru.vyarus.animalsniffer") version "1.5.3" apply false
|
||||
id("me.champeau.gradle.japicmp") version "0.2.9" apply false
|
||||
}
|
||||
|
||||
@@ -44,50 +43,47 @@ spotless {
|
||||
indentWithSpaces(2)
|
||||
endWithNewline()
|
||||
}
|
||||
// GJF not compatible with JDK 15 yet
|
||||
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_15)) {
|
||||
val externalJavaFiles = arrayOf(
|
||||
"**/ClassFactory.java",
|
||||
"**/Iso8601Utils.java",
|
||||
"**/JsonReader.java",
|
||||
"**/JsonReaderPathTest.java",
|
||||
"**/JsonReaderTest.java",
|
||||
"**/JsonScope.java",
|
||||
"**/JsonUtf8Reader.java",
|
||||
"**/JsonUtf8ReaderPathTest.java",
|
||||
"**/JsonUtf8ReaderTest.java",
|
||||
"**/JsonUtf8ReaderTest.java",
|
||||
"**/JsonUtf8Writer.java",
|
||||
"**/JsonUtf8WriterTest.java",
|
||||
"**/JsonWriter.java",
|
||||
"**/JsonWriterPathTest.java",
|
||||
"**/JsonWriterTest.java",
|
||||
"**/LinkedHashTreeMap.java",
|
||||
"**/LinkedHashTreeMapTest.java",
|
||||
"**/PolymorphicJsonAdapterFactory.java",
|
||||
"**/RecursiveTypesResolveTest.java",
|
||||
"**/Types.java",
|
||||
"**/TypesTest.java"
|
||||
val externalJavaFiles = arrayOf(
|
||||
"**/ClassFactory.java",
|
||||
"**/Iso8601Utils.java",
|
||||
"**/JsonReader.java",
|
||||
"**/JsonReaderPathTest.java",
|
||||
"**/JsonReaderTest.java",
|
||||
"**/JsonScope.java",
|
||||
"**/JsonUtf8Reader.java",
|
||||
"**/JsonUtf8ReaderPathTest.java",
|
||||
"**/JsonUtf8ReaderTest.java",
|
||||
"**/JsonUtf8ReaderTest.java",
|
||||
"**/JsonUtf8Writer.java",
|
||||
"**/JsonUtf8WriterTest.java",
|
||||
"**/JsonWriter.java",
|
||||
"**/JsonWriterPathTest.java",
|
||||
"**/JsonWriterTest.java",
|
||||
"**/LinkedHashTreeMap.java",
|
||||
"**/LinkedHashTreeMapTest.java",
|
||||
"**/PolymorphicJsonAdapterFactory.java",
|
||||
"**/RecursiveTypesResolveTest.java",
|
||||
"**/Types.java",
|
||||
"**/TypesTest.java"
|
||||
)
|
||||
val configureCommonJavaFormat: JavaExtension.() -> Unit = {
|
||||
googleJavaFormat("1.11.0")
|
||||
}
|
||||
java {
|
||||
configureCommonJavaFormat()
|
||||
target("**/*.java")
|
||||
targetExclude(
|
||||
"**/spotless.java",
|
||||
"**/build/**",
|
||||
*externalJavaFiles
|
||||
)
|
||||
val configureCommonJavaFormat: JavaExtension.() -> Unit = {
|
||||
googleJavaFormat("1.7")
|
||||
}
|
||||
java {
|
||||
configureCommonJavaFormat()
|
||||
target("**/*.java")
|
||||
targetExclude(
|
||||
"**/spotless.java",
|
||||
"**/build/**",
|
||||
*externalJavaFiles
|
||||
)
|
||||
licenseHeaderFile("spotless/spotless.java")
|
||||
}
|
||||
format("externalJava", JavaExtension::class.java) {
|
||||
// These don't use our spotless config for header files since we don't want to overwrite the
|
||||
// existing copyright headers.
|
||||
configureCommonJavaFormat()
|
||||
target(*externalJavaFiles)
|
||||
}
|
||||
licenseHeaderFile("spotless/spotless.java")
|
||||
}
|
||||
format("externalJava", JavaExtension::class.java) {
|
||||
// These don't use our spotless config for header files since we don't want to overwrite the
|
||||
// existing copyright headers.
|
||||
configureCommonJavaFormat()
|
||||
target(*externalJavaFiles)
|
||||
}
|
||||
kotlin {
|
||||
ktlint(Dependencies.ktlintVersion).userData(mapOf("indent_size" to "2"))
|
||||
@@ -129,15 +125,14 @@ subprojects {
|
||||
// Apply with "java" instead of just "java-library" so kotlin projects get it too
|
||||
pluginManager.withPlugin("java") {
|
||||
configure<JavaPluginExtension> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(16))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("ru.vyarus.animalsniffer") {
|
||||
dependencies {
|
||||
"compileOnly"(Dependencies.AnimalSniffer.annotations)
|
||||
"signature"(Dependencies.AnimalSniffer.java7Signature)
|
||||
if (project.name != "records-tests") {
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release.set(8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +141,7 @@ subprojects {
|
||||
kotlinOptions {
|
||||
@Suppress("SuspiciousCollectionReassignment")
|
||||
freeCompilerArgs += listOf("-progressive")
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user