mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Modernize build a bit (#1383)
This commit is contained in:
@@ -22,14 +22,15 @@ plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("kapt")
|
||||
id("com.vanniktech.maven.publish")
|
||||
id("com.github.johnrengelman.shadow") version "7.0.0"
|
||||
alias(libs.plugins.mavenShadow)
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
@Suppress("SuspiciousCollectionReassignment")
|
||||
freeCompilerArgs += listOf(
|
||||
"-Xopt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview"
|
||||
"-Xopt-in=kotlin.RequiresOptIn",
|
||||
"-Xopt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -57,38 +58,38 @@ dependencies {
|
||||
// https://youtrack.jetbrains.com/issue/KT-41702
|
||||
api(project(":moshi"))
|
||||
api(kotlin("reflect"))
|
||||
shade(Dependencies.Kotlin.metadata) {
|
||||
shade(libs.kotlinxMetadata) {
|
||||
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
|
||||
}
|
||||
api(Dependencies.KotlinPoet.kotlinPoet)
|
||||
shade(Dependencies.KotlinPoet.metadata) {
|
||||
api(libs.kotlinpoet)
|
||||
shade(libs.kotlinpoet.metadata.core) {
|
||||
exclude(group = "org.jetbrains.kotlin")
|
||||
exclude(group = "com.squareup", module = "kotlinpoet")
|
||||
}
|
||||
shade(Dependencies.KotlinPoet.metadataSpecs) {
|
||||
shade(libs.kotlinpoet.metadata.specs) {
|
||||
exclude(group = "org.jetbrains.kotlin")
|
||||
exclude(group = "com.squareup", module = "kotlinpoet")
|
||||
}
|
||||
api(Dependencies.KotlinPoet.elementsClassInspector)
|
||||
shade(Dependencies.KotlinPoet.elementsClassInspector) {
|
||||
api(libs.kotlinpoet.elementsClassInspector)
|
||||
shade(libs.kotlinpoet.elementsClassInspector) {
|
||||
exclude(group = "org.jetbrains.kotlin")
|
||||
exclude(group = "com.squareup", module = "kotlinpoet")
|
||||
exclude(group = "com.google.guava")
|
||||
}
|
||||
api(Dependencies.asm)
|
||||
api(libs.asm)
|
||||
|
||||
api(Dependencies.AutoService.annotations)
|
||||
kapt(Dependencies.AutoService.processor)
|
||||
api(Dependencies.Incap.annotations)
|
||||
kapt(Dependencies.Incap.processor)
|
||||
api(libs.autoService)
|
||||
kapt(libs.autoService.processor)
|
||||
api(libs.incap)
|
||||
kapt(libs.incap.processor)
|
||||
|
||||
// Copy these again as they're not automatically included since they're shaded
|
||||
testImplementation(Dependencies.KotlinPoet.metadata)
|
||||
testImplementation(Dependencies.KotlinPoet.metadataSpecs)
|
||||
testImplementation(Dependencies.KotlinPoet.elementsClassInspector)
|
||||
testImplementation(Dependencies.Testing.junit)
|
||||
testImplementation(Dependencies.Testing.truth)
|
||||
testImplementation(Dependencies.Testing.compileTesting)
|
||||
testImplementation(libs.kotlinpoet.metadata.core)
|
||||
testImplementation(libs.kotlinpoet.metadata.specs)
|
||||
testImplementation(libs.kotlinpoet.elementsClassInspector)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.truth)
|
||||
testImplementation(libs.kotlinCompileTesting)
|
||||
}
|
||||
|
||||
val relocateShadowJar = tasks.register<ConfigureShadowRelocation>("relocateShadowJar") {
|
||||
|
@@ -85,7 +85,10 @@ internal class AdapterGenerator(
|
||||
// KotlinPoet always generates explicit public modifiers for public members.
|
||||
"RedundantVisibilityModifier",
|
||||
// For LambdaTypeNames we have to import kotlin.functions.* types
|
||||
"PLATFORM_CLASS_MAPPED_TO_KOTLIN"
|
||||
"PLATFORM_CLASS_MAPPED_TO_KOTLIN",
|
||||
// Cover for calling fromJson() on a Nothing property type. Theoretically nonsensical but we
|
||||
// support it
|
||||
"IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION"
|
||||
).let { suppressions ->
|
||||
AnnotationSpec.builder(Suppress::class)
|
||||
.useSiteTarget(FILE)
|
||||
|
@@ -23,6 +23,7 @@ import com.squareup.kotlinpoet.CHAR
|
||||
import com.squareup.kotlinpoet.ClassName
|
||||
import com.squareup.kotlinpoet.CodeBlock
|
||||
import com.squareup.kotlinpoet.DOUBLE
|
||||
import com.squareup.kotlinpoet.DelicateKotlinPoetApi
|
||||
import com.squareup.kotlinpoet.FLOAT
|
||||
import com.squareup.kotlinpoet.INT
|
||||
import com.squareup.kotlinpoet.KModifier
|
||||
@@ -79,6 +80,7 @@ internal fun TypeName.defaultPrimitiveValue(): CodeBlock =
|
||||
else -> CodeBlock.of("null")
|
||||
}
|
||||
|
||||
@OptIn(DelicateKotlinPoetApi::class)
|
||||
internal fun TypeName.asTypeBlock(): CodeBlock {
|
||||
if (annotations.isNotEmpty()) {
|
||||
return copy(annotations = emptyList()).asTypeBlock()
|
||||
|
@@ -17,6 +17,7 @@ package com.squareup.moshi.kotlin.codegen
|
||||
|
||||
import com.squareup.kotlinpoet.AnnotationSpec
|
||||
import com.squareup.kotlinpoet.ClassName
|
||||
import com.squareup.kotlinpoet.DelicateKotlinPoetApi
|
||||
import com.squareup.kotlinpoet.KModifier
|
||||
import com.squareup.kotlinpoet.LambdaTypeName
|
||||
import com.squareup.kotlinpoet.ParameterizedTypeName
|
||||
@@ -117,6 +118,7 @@ internal fun primaryConstructor(
|
||||
}
|
||||
|
||||
/** Returns a target type for `element`, or null if it cannot be used with code gen. */
|
||||
@OptIn(DelicateKotlinPoetApi::class)
|
||||
@KotlinPoetMetadataPreview
|
||||
internal fun targetType(
|
||||
messager: Messager,
|
||||
@@ -233,7 +235,6 @@ internal fun targetType(
|
||||
val resolvedTypes = mutableListOf<ResolvedTypeMapping>()
|
||||
val superTypes = appliedType.supertypes(types)
|
||||
.filterNot { supertype ->
|
||||
@Suppress("DEPRECATION") // Appropriate in this case
|
||||
supertype.element.asClassName() == OBJECT_CLASS || // Don't load properties for java.lang.Object.
|
||||
supertype.element.kind != ElementKind.CLASS // Don't load properties for interface types.
|
||||
}
|
||||
@@ -273,7 +274,6 @@ internal fun targetType(
|
||||
val superSuperClass = supertype.element.superclass as DeclaredType
|
||||
|
||||
// Convert to an element and back to wipe the typed generics off of this
|
||||
@Suppress("DEPRECATION") // Appropriate in this case
|
||||
val untyped = superSuperClass.asElement().asType().asTypeName() as ParameterizedTypeName
|
||||
resolvedTypes += ResolvedTypeMapping(
|
||||
target = untyped.rawType,
|
||||
@@ -289,7 +289,6 @@ internal fun targetType(
|
||||
}
|
||||
|
||||
for ((localAppliedType, supertypeApi) in superTypes.entries) {
|
||||
@Suppress("DEPRECATION") // Appropriate in this case
|
||||
val appliedClassName = localAppliedType.element.asClassName()
|
||||
val supertypeProperties = declaredProperties(
|
||||
constructor = constructor,
|
||||
@@ -317,7 +316,6 @@ internal fun targetType(
|
||||
if (forceInternal) KModifier.INTERNAL else visibility
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") // Appropriate in this case
|
||||
return TargetType(
|
||||
typeName = element.asType().asTypeName(),
|
||||
constructor = constructor,
|
||||
|
Reference in New Issue
Block a user