When generating a new Spring Boot project using the web Spring Boot Initializer, with the Kotlin language, the generated Gradle configuration looks broken, I cannot run any task, I am getting the following errors
./gradlew jar
> Configure project :
e: /home/mpoussin/Documents/Repositories/platform-core/build.gradle.kts:52:14: Unresolved reference: snippetsDir
e: /home/mpoussin/Documents/Repositories/platform-core/build.gradle.kts:56:13: Unresolved reference: snippetsDir
e: /home/mpoussin/Documents/Repositories/platform-core/build.gradle.kts:57:12: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val NamedDomainObjectContainer<KotlinSourceSet>.test: NamedDomainObjectProvider<KotlinSourceSet> defined in org.gradle.kotlin.dsl
public val SourceSetContainer.test: NamedDomainObjectProvider<SourceSet> defined in org.gradle.kotlin.dsl
public val TaskContainer.test: TaskProvider<Test> defined in org.gradle.kotlin.dsl
FAILURE: Build failed with an exception.
* Where:
Build file '/home/mpoussin/Documents/Repositories/platform-core/build.gradle.kts' line: 52
* What went wrong:
Script compilation errors:
Line 52: outputs.dir(snippetsDir)
^ Unresolved reference: snippetsDir
Line 56: inputs.dir(snippetsDir)
^ Unresolved reference: snippetsDir
Line 57: dependsOn(test)
^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val NamedDomainObjectContainer<KotlinSourceSet>.test: NamedDomainObjectProvider<KotlinSourceSet> defined in org.gradle.kotlin.dsl
public val SourceSetContainer.test: NamedDomainObjectProvider<SourceSet> defined in org.gradle.kotlin.dsl
public val TaskContainer.test: TaskProvider<Test> defined in org.gradle.kotlin.dsl
3 errors
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 924ms
This is the generated gradle configuration as provided in the generated zip file by spring initializer:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.4.0"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
id("org.asciidoctor.convert") version "1.5.8"
kotlin("jvm") version "1.4.10"
kotlin("plugin.spring") version "1.4.10"
kotlin("plugin.jpa") version "1.4.10"
}
group = "tech.xxxx.platform"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
extra["snippetsDir"] = file("build/generated-snippets")
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.boot:spring-boot-starter-hateoas")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-validation")
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("org.liquibase:liquibase-core")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")
testImplementation("org.springframework.security:spring-security-test")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.test {
outputs.dir(snippetsDir)
}
tasks.asciidoctor {
inputs.dir(snippetsDir)
dependsOn(test)
}
My versions :
java --version
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment Zulu15.28+51-CA (build 15.0.1+9)
OpenJDK 64-Bit Server VM Zulu15.28+51-CA (build 15.0.1+9, mixed mode, sharing)
./gradlew --version
------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------
Build time: 2020-08-25 16:29:12 UTC
Revision: f2d1fb54a951d8b11d25748e4711bec8d128d7e3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 15.0.1 (Azul Systems, Inc. 15.0.1+9)
OS: Linux 5.4.0-54-generic amd64
Distribution : Mint 20 (Ubuntu Focal)
Also it looks like that it keeps targeting JVM 11 even when selecting JVM 15 on the web interface (just retried now with another project and it's doing the same)
Comment From: snicoll
@kedare thanks for the report but that's the wrong issue tracker to report the problem.
It's not a new Gradle project but a specific project using Spring REST Docs as this includes a customization for the snippetsDir that looks incorrect with more recent Gradle version. We need to figure out why the integration test didn't caught that.
I am going to move this issue to the start.spring.io issue tracker as this customisation is defined there. We may have to create a separate issue in the Spring Initializr project if it turns out our Kotlin DSL is missing a feature.
Comment From: snicoll
Unfortunately, I cannot transfer this issue to another organisation, please watch https://github.com/spring-io/start.spring.io/issues/581 for updates.
Also it looks like that it keeps targeting JVM 11 even when selecting JVM 15 on the web interface
That's the JVM target level and Kotlin did not have an option for Java 15 back then. I can see it does now so we need to lift that limitation (although it shouldn't make any difference for you if you're using Kotlin anyway). I've created https://github.com/spring-io/start.spring.io/issues/582
Comment From: kedare
Thanks, I will watch those tickets, I was not really sure where to report it :)
Sent with GitHawk