mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Prepare project for Kotlin migration (#1257)
This commit is contained in:
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("com.vanniktech.maven.publish")
|
||||
id("ru.vyarus.animalsniffer")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>()
|
||||
@@ -26,18 +27,14 @@ tasks.withType<KotlinCompile>()
|
||||
.configureEach {
|
||||
kotlinOptions {
|
||||
@Suppress("SuspiciousCollectionReassignment") // It's not suspicious
|
||||
freeCompilerArgs += listOf(
|
||||
"-Xopt-in=kotlin.ExperimentalStdlibApi"
|
||||
)
|
||||
freeCompilerArgs += listOf("-Xopt-in=kotlin.ExperimentalStdlibApi")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(Dependencies.jsr305)
|
||||
compileOnly(Dependencies.Kotlin.stdlib)
|
||||
api(Dependencies.okio)
|
||||
|
||||
testImplementation(Dependencies.Kotlin.stdlib)
|
||||
testCompileOnly(Dependencies.jsr305)
|
||||
testImplementation(Dependencies.Testing.junit)
|
||||
testImplementation(Dependencies.Testing.truth)
|
||||
|
@@ -18,7 +18,3 @@ POM_NAME=Moshi
|
||||
POM_ARTIFACT_ID=moshi
|
||||
POM_PACKAGING=jar
|
||||
AUTOMATIC_MODULE_NAME=com.squareup.moshi
|
||||
|
||||
# Kotlin adds the stdlib dep by default in 1.4.0+, but we want to effectively make it compileOnly
|
||||
# for our case to avoid imposing it on consumers.
|
||||
kotlin.stdlib.default.dependency=false
|
||||
|
53
moshi/japicmp/build.gradle.kts
Normal file
53
moshi/japicmp/build.gradle.kts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Square, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import me.champeau.gradle.japicmp.JapicmpTask
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
id("me.champeau.gradle.japicmp")
|
||||
}
|
||||
|
||||
val baseline = configurations.create("baseline")
|
||||
val latest = configurations.create("latest")
|
||||
|
||||
dependencies {
|
||||
baseline("com.squareup.moshi:moshi:1.11.0") {
|
||||
isTransitive = false
|
||||
isForce = true
|
||||
}
|
||||
latest(project(":moshi"))
|
||||
}
|
||||
|
||||
val japicmp = tasks.register<JapicmpTask>("japicmp") {
|
||||
dependsOn("jar")
|
||||
oldClasspath = baseline
|
||||
newClasspath = latest
|
||||
onlyBinaryIncompatibleModified = true
|
||||
failOnModification = true
|
||||
txtOutputFile = file("$buildDir/reports/japi.txt")
|
||||
ignoreMissingClasses = true
|
||||
includeSynthetic = true
|
||||
classExcludes = listOf(
|
||||
"com.squareup.moshi.internal.NonNullJsonAdapter", // Internal.
|
||||
"com.squareup.moshi.internal.NullSafeJsonAdapter", // Internal.
|
||||
"com.squareup.moshi.internal.Util" // Internal.
|
||||
)
|
||||
}
|
||||
|
||||
tasks.named("check").configure {
|
||||
dependsOn(japicmp)
|
||||
}
|
@@ -26,17 +26,17 @@ import kotlin.reflect.typeOf
|
||||
* itself is handled, nested types (such as in generics) are not resolved.
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
inline fun <reified T> Moshi.adapter(): JsonAdapter<T> = adapter(typeOf<T>())
|
||||
public inline fun <reified T> Moshi.adapter(): JsonAdapter<T> = adapter(typeOf<T>())
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
inline fun <reified T> Moshi.Builder.addAdapter(adapter: JsonAdapter<T>): Moshi.Builder = add(typeOf<T>().javaType, adapter)
|
||||
public inline fun <reified T> Moshi.Builder.addAdapter(adapter: JsonAdapter<T>): Moshi.Builder = add(typeOf<T>().javaType, adapter)
|
||||
|
||||
/**
|
||||
* @return a [JsonAdapter] for [ktype], creating it if necessary. Note that while nullability of
|
||||
* [ktype] itself is handled, nested types (such as in generics) are not resolved.
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
fun <T> Moshi.adapter(ktype: KType): JsonAdapter<T> {
|
||||
public fun <T> Moshi.adapter(ktype: KType): JsonAdapter<T> {
|
||||
val adapter = adapter<T>(ktype.javaType)
|
||||
return if (adapter is NullSafeJsonAdapter || adapter is NonNullJsonAdapter) {
|
||||
// TODO CR - Assume that these know what they're doing? Or should we defensively avoid wrapping for matching nullability?
|
||||
|
@@ -25,13 +25,13 @@ import kotlin.reflect.javaType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
/** Returns the raw [Class] type of this type. */
|
||||
val Type.rawType: Class<*> get() = Types.getRawType(this)
|
||||
public val Type.rawType: Class<*> get() = Types.getRawType(this)
|
||||
|
||||
/**
|
||||
* Checks if [this] contains [T]. Returns the subset of [this] without [T], or null if
|
||||
* [this] does not contain [T].
|
||||
*/
|
||||
inline fun <reified T : Annotation> Set<Annotation>.nextAnnotations(): Set<Annotation>? = Types.nextAnnotations(this, T::class.java)
|
||||
public inline fun <reified T : Annotation> Set<Annotation>.nextAnnotations(): Set<Annotation>? = Types.nextAnnotations(this, T::class.java)
|
||||
|
||||
/**
|
||||
* Returns a type that represents an unknown type that extends [T]. For example, if
|
||||
@@ -39,7 +39,7 @@ inline fun <reified T : Annotation> Set<Annotation>.nextAnnotations(): Set<Annot
|
||||
* [T] is [Any], this returns `*`, which is shorthand for `out Any?`.
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
inline fun <reified T> subtypeOf(): WildcardType {
|
||||
public inline fun <reified T> subtypeOf(): WildcardType {
|
||||
var type = typeOf<T>().javaType
|
||||
if (type is Class<*>) {
|
||||
type = Util.boxIfPrimitive(type)
|
||||
@@ -52,7 +52,7 @@ inline fun <reified T> subtypeOf(): WildcardType {
|
||||
* [String], this returns `in String`.
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
inline fun <reified T> supertypeOf(): WildcardType {
|
||||
public inline fun <reified T> supertypeOf(): WildcardType {
|
||||
var type = typeOf<T>().javaType
|
||||
if (type is Class<*>) {
|
||||
type = Util.boxIfPrimitive(type)
|
||||
@@ -62,10 +62,10 @@ inline fun <reified T> supertypeOf(): WildcardType {
|
||||
|
||||
/** Returns a [GenericArrayType] with [this] as its [GenericArrayType.getGenericComponentType]. */
|
||||
@ExperimentalStdlibApi
|
||||
fun KType.asArrayType(): GenericArrayType = javaType.asArrayType()
|
||||
public fun KType.asArrayType(): GenericArrayType = javaType.asArrayType()
|
||||
|
||||
/** Returns a [GenericArrayType] with [this] as its [GenericArrayType.getGenericComponentType]. */
|
||||
fun KClass<*>.asArrayType(): GenericArrayType = java.asArrayType()
|
||||
public fun KClass<*>.asArrayType(): GenericArrayType = java.asArrayType()
|
||||
|
||||
/** Returns a [GenericArrayType] with [this] as its [GenericArrayType.getGenericComponentType]. */
|
||||
fun Type.asArrayType(): GenericArrayType = Types.arrayOf(this)
|
||||
public fun Type.asArrayType(): GenericArrayType = Types.arrayOf(this)
|
||||
|
Reference in New Issue
Block a user