KotshiApplicationJsonAdapterFactory does not have a companion object
nicofari opened this issue · comments
Hi
I am totally new to moshi/kotshi
I was following the readme of this project.
Adding the line
@KotshiJsonAdapterFactory
object ApplicationJsonAdapterFactory : JsonAdapter.Factory by KotshiApplicationJsonAdapterFactory
I got the error
Classifier 'KotshiJsonAdapterFactory' does not have a companion object, and thus must be initialized here
I checked other examples but haven't found any clue ...
thanks for any help/tips
Some things to verify:
- You've added both the API and the compiler dependencies
- Are the imports correct (please post the entire file)
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "${kotlinVersion}"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.google.devtools.ksp" version "1.8.10-1.0.9"
}
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "java"
repositories {
mavenCentral()
}
compileKotlin.kotlinOptions.jvmTarget = "11"
compileTestKotlin.kotlinOptions.jvmTarget = "11"
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
test {
useJUnitPlatform()
testLogging.showStandardStreams = true
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
implementation platform("org.http4k:http4k-bom:${http4kVersion}")
implementation "org.http4k:http4k-core"
implementation "org.http4k:http4k-serverless-lambda"
implementation "org.http4k:http4k-cloudnative"
implementation "org.http4k:http4k-contract"
implementation("org.http4k:http4k-format-moshi") {
exclude group: "org.jetbrains.kotlin", module: "kotlin-reflect"
}
implementation("se.ansman.kotshi:api:$kotshiVersion")
ksp("se.ansman.kotshi:compiler:$kotshiVersion")
implementation "org.http4k:http4k-opentelemetry:${http4kVersion}"
implementation "org.apache.pdfbox:pdfbox:2.0.27"
implementation "de.redsix:pdfcompare:1.1.61"
implementation "net.sf.barcode4j:barcode4j:2.1"
testImplementation platform("org.junit:junit-bom:${junitVersion}")
testImplementation "org.http4k:http4k-testing-hamkrest"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-engine"
}
shadowJar {
manifest.attributes['Main-Class'] = 'it.multidialogo.multiprinter.MultiprinterKt'
archiveBaseName.set("multiprinter")
archiveClassifier.set(null)
archiveVersion.set(null)
mergeServiceFiles()
}
task buildZip(type: Zip) {
from compileKotlin
from processResources
into('lib') {
from configurations.compileClasspath
}
}
in gradle.properties i have:
junitVersion=5.7.2
kotlinVersion=1.8.10
http4kVersion=4.41.0.0
kotshiVersion=2.10.2
If I understand well (I am reading this example: https://github.com/oharaandrew314/http4k-api-on-lambda) I have to use a factory name that does not exist, it has to been generated by kotshi.
But when I issue gradlew clean assemble it does not generated in my project
while, in that project, it does ...
don't understand which task in the gradle file generates it though ...
I've found that, if i use "gradlew clean compileKotlin" the code is generated (thought "assemble" would execute everything before)
Yeah, you need to build once for the code to be generated.