TestEntityManager not found in Spring Boot Kotlin Tutorial in IntelliJ - spring

I thoroughly followed this tutorial, step-by-step.
I get this error in IntelliJ idea.
It's probably an IDE quirk, since the tests are actually running just fine.
I'm using Java 11 and the following dependecies versions:
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-mustache")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
plugins {
id("org.springframework.boot") version "2.7.1"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
kotlin("plugin.jpa") version "1.6.21"
kotlin("plugin.allopen") version "1.4.32"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
java.sourceCompatibility = JavaVersion.VERSION_11
I can't find anything to get rid of this annoying red highlight.

Related

Unresolved symbol:mainClassName

I have a SpringBoot project with the following build.gradle:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.7.0"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.7.0"
kotlin("plugin.spring") version "1.7.0"
kotlin("plugin.jpa") version "1.6.21"
id("org.flywaydb.flyway") version "6.4.4"
}
group = "com.planes"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.tomcat.embed:tomcat-embed-jasper")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.jsonwebtoken:jjwt:0.9.0")
implementation("org.postgresql:postgresql")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("org.springframework.security:spring-security-test")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
springBoot {
mainClassName = "com.planes.planesserver.DemoApplication"
}
When I run the Gradle Wrapper Task I get the following error: "Unresolved reference: mainClassName"
This happens after I updated SpringBoot from Version 2.2 to 2.7 and gradle from version 5 to version 6.9.3
In the previous configuration the project could compile just fine. Are there any adjustments I need to still make for this new configuration ?
Can anyone please give a suggestion ?
In Springboot 2.4 they changed the name and type of the main classname property, see in Springboot 2.4 Release notes:
You need to update your build script as follows :
springBoot {
// before springboot 2.4
// mainClassName = "com.planes.planesserver.DemoApplication"
// since springboot 2.4 :
mainClass.set( "com.planes.planesserver.DemoApplication")
}

Error: "Unresolved reference: listOf" in gradle.kts

I install spring-boot with settings: project: gradle, language: kotlin, Spring Boot: 3.0.0, Java: 11. And when build project saw this error: "Unresolved reference: listOf".(listOf work in kt files)
plugins {
id("org.springframework.boot") version "3.0.0-SNAPSHOT"
id("io.spring.dependency-management") version "1.0.13.RELEASE"
kotlin("jvm") version "1.7.10"
kotlin("plugin.spring") version "1.7.10"
kotlin("plugin.jpa") version "1.7.10"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/milestone") }
maven { url = uri("https://repo.spring.io/snapshot") }
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
Project settings enter image description here

Not able download dependencies in build.gradle.kts file using intellij

I am doing a Spring Boot Kotlin Project. Here is my build.gradle.kts file.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.8.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.axis"
version = "0.0.1-SNAPSHOT"
//java.sourceCompatibility = JavaVersion.VERSION_1_8
val compileKotlin: KotlinCompile by tasks
val compileTestKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.kafka:spring-kafka")
implementation("com.google.code.gson:gson")
implementation("com.itextpdf:itextpdf:5.0.6")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
testImplementation("io.projectreactor:reactor-test")
testImplementation("io.mockk:mockk:1.9.3")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
I am adding the mockk dependency but it is not getting downloaded. Neither of the dependencies are getting downloaded. The build is successful but the dependency which I add don't get downloaded. I have disabled my proxy and tried.
I have checked the below link and tried out. But it doesn't work
Gradle build doesn't download dependencies
Any help will be appreciated.
I was able to resolve this. When i switched to a different network i was able to download. Not sure as to why i was being blocked to download dependencies in some network.

How to import amazon s3 for spring boot using gradle kotlin dsl

I have tried to import s3 in my spring boot project following the instructions on the official docs but the dependencies aren't being resolved. https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/setup-project-gradle.html
I updated the software.amazon.awssdk:bom from the documentation to the latest 2.7.16 hoping this will fix it.
this is my build.gradle.kts file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("plugin.jpa") version "1.3.31"
id("org.springframework.boot") version "2.1.5.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.3.31"
kotlin("plugin.spring") version "1.3.31"
kotlin("plugin.noarg") version "1.3.31"
}
allOpen {
annotation("javax.persistence.Entity")
annotation("javax.persistence.MappedSuperclass")
annotation("javax.persistence.Embeddable")
}
noArg {
annotation("javax.persistence.Entity")
}
group = "com.leaveentry"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.google.api-client:google-api-client:1.25.0")
implementation("io.jsonwebtoken:jjwt-api:0.10.5")
implementation(platform("software.amazon.awssdk:bom:2.7.16"))
implementation("software.amazon.awssdk:s3")
runtimeOnly("com.h2database:h2")
runtimeOnly("mysql:mysql-connector-java")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.10.5")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.10.5")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
When I try to import s3 related classes, they are not resolved.
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.CannedAccessControlList
import com.amazonaws.services.s3.model.PutObjectRequest
I've had similar issues and although I didn't manage to make that specific version of amazon bom work, I found a workaround.
Add to your build.gradle.kts the following lines:
dependencyManagement {
imports {
mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.228")
}
}
and the following implementation inside the dependencies block:
implementation("software.amazon.awssdk:s3:2.10.1")
Note: Alternatively, you can add the following if you want to include all the services at once:
implementation("software.amazon.awssdk:aws-sdk-java:2.10.1")

Kotlin: Cannot inline bytecode built with JVM target 1.8 into byte code with JVM target 1.6

I have an issue when trying to add a few dependencies to my kotlin spring project. I used the spring boot initializer to get a basic project running.
My problem: If I uncomment jackson or either Koin dependency then my build fails with the mentioned in the titile
Here is the build.gradle.kts file :
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("plugin.jpa") version "1.3.31"
id("org.springframework.boot") version "2.2.0.M4"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.3.31"
kotlin("plugin.spring") version "1.3.31"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
}
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/snapshot") }
maven { url = uri("https://repo.spring.io/milestone") }
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
exclude(group = "junit", module = "junit")
}
// jackson
//implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.+")
// Koin
//implementation("org.koin:koin-core:2.0.1")
// Koin Test
//implementation("org.koin:koin-test:2.0.1")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
I Have already tried all the solutions from this previous question someone else asked: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
I already had the KotlinCompile jvmTarget option in there and it has been set in my build settings as well. Any help is appreciated thanks!
A lot of the answers to this are android specific - using kotlin to write a spring boot app isn't that well documented or supported but still awesome. This setting in intelij cleared this error for me - hope it helps someone, my kotlin compiler had a target set to 1.6:

Resources