Stack Exchange
How do I build a constructor where the field is `var` and can be `@annotated`?
How do I use Kotlinpoet to generate the following code?
data class Test (
  @Id
  var id: Long
) : Interface {
  override fun primaryKey() : Serializable = this
}


What have you tried so far? Are you stuck somewhere?

Unit tests are a great source of KotlinPoet recipes: https://github.com/square/kotlinpoet/blob/f3a35362f7bac6cf01372ece4372390882a41eed/kotlinpoet/src/test/java/com/squareup/kotlinpoet/TypeSpecTest.kt#L247

You can try
FileSpec
                .builder(packageName, actionName)
                .addType(TypeSpec.classBuilder(actionName)
                        .primaryConstructor(FunSpec.constructorBuilder()
                                .addParameter(ParameterSpec.builder("aName", String::class.java)
                                        .addAnnotation(Id::class.java)
                                        .build())
                                .build()).build())


with Yrii‘s answer, you also need call
addProperty(PropertySpec.builder("id",Long::class).initializer("id").build())

