Folks, I'm using kotlin with spring boot 2.0.0.RC1...
# getting-started
j
Folks, I'm using kotlin with spring boot 2.0.0.RC1. I use the gradle and the no-arg constructor plugin and I apply the kotlin-jpa plugin but nevertheless I get the "No default constructor error". What could this be caused by?
Copy code
import javax.persistence.Entity
import javax.persistence.Id
import javax.persistence.GeneratedValue

@Entity
data class Todo(@Id @GeneratedValue val id: Int,
           val description: String,
           val completed: Boolean) {
}
Copy code
buildscript {

	ext {
		kotlinVersion = '1.2.21'
		springBootVersion = '2.0.0.RC1'
	}
	repositories {
		mavenCentral()
		maven { url "<https://repo.spring.io/snapshot>" }
		maven { url "<https://repo.spring.io/milestone>" }
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
		classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
		classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
        classpath "org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}"
	}
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: "kotlin-noarg"
apply plugin: "kotlin-jpa"
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


noArg {
    annotation("javax.parstyarsersistence.Entity")
}sourceCompatibility = 1.8
compileKotlin {
	kotlinOptions {
		freeCompilerArgs = ["-Xjsr305=strict"]
		jvmTarget = "1.8"
	}
}
compileTestKotlin {
	kotlinOptions {
		freeCompilerArgs = ["-Xjsr305=strict"]
		jvmTarget = "1.8"
	}
}

repositories {
	mavenCentral()
	maven { url "<https://repo.spring.io/snapshot>" }
	maven { url "<https://repo.spring.io/milestone>" }
}


dependencies {
	compile('org.springframework.boot:spring-boot-starter-data-jpa')
	compile('org.springframework.boot:spring-boot-starter-hateoas')
	compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
	compile("org.jetbrains.kotlin:kotlin-reflect")
	compile("com.fasterxml.jackson.module:jackson-module-kotlin")
	runtime group: 'com.h2database', name: 'h2'
    compile("org.springframework.boot:spring-boot-devtools")
	testCompile('org.springframework.boot:spring-boot-starter-test')
}
j
Maybe the package of annotation in noArg gradle settings is not correct
m
@jesjos From what I can see, what is missing is the assignment of the variables... Since it's a data class, you need to assign values to every property.. Like "data class Example(@Id val id: Long = 0)" and so on...
Btw for Spring JPA entities, make sure the @Id nullable... Like "val id: Long? = null" or you will face some problems commiting new instances of the entity to the database. You don't need to pay much attention to the other fields though (except the ones that are nullable on the db).