I have a multi-module project with following structure
When I try to build signal-site project I get this Exception
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all task dependencies for configuration ':runtimeClasspath'.
settings.gradle.kts (trade) - top level
rootProject.name = "trade"
include("trade-common")
include("signal-site")
build.gradle.kts (trade) - top level
group = "com.oleinikdi"
version = "1.0"
subprojects {
version = "1.0"
}
allprojects {
repositories {
jcenter()
}
}
settings.gradle.kts (trade-common)
rootProject.name = "trade-common"
build.gradle.kts (trade-common)
subprojects {
version = "1.0"
}
plugins {
kotlin("jvm") version "1.3.70"
}
group = "com.oleinikdi"
version = "1.0"
repositories {
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
}
settings.gradle.kts (signal-site)
rootProject.name = "signal-site"
include("trade-common")
build.gradle.kts (signal-site)
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
subprojects {
version = "1.0"
}
plugins {
id("org.springframework.boot") version "2.2.5.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
war
kotlin("jvm") version "1.3.70"
kotlin("plugin.spring") version "1.3.70"
kotlin("plugin.jpa") version "1.3.70"
}
group = "com.oleinik"
version = "1.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
jcenter()
}
dependencies {
implementation(project(":trade-common"))
providedRuntime("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-data-rest")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-security")
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")
implementation("org.liquibase:liquibase-core")
// runtimeOnly("org.postgresql:postgresql")
implementation("org.postgresql:postgresql")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
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"
}
}
In a multi project build, there must be only one settings.gradle file at the root of the project.
So your issue is caused by having multiple settings.gradle defined in your hierarchy, which means when running something in signal-site, Gradle is configured to look for trade-common as a subfolder of signal-site.
Simply remove the trade-common and signal-site settings.gradle files, leaving only the one at the root.
See the documentation to get a deeper understanding of Gradle settings.gradle files and how they work in multi project setups.
Related
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
I am trying to create a gradle multi project in spring boot and kotlin. Using gradle kotlin scripts to write build file. This is my root project's build file (build.gradle.kts).
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
val kotlinVersion = "1.4.10"
val springBootVersion = "2.3.4.RELEASE"
val springDependencyManagementVersion = "1.0.10.RELEASE"
id("org.springframework.boot") version springBootVersion apply false
id("io.spring.dependency-management") version springDependencyManagementVersion apply false
kotlin("jvm") version kotlinVersion
kotlin("kapt") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion apply false
}
allprojects {
repositories {
jcenter()
}
group = "org.example"
version = "1.0-SNAPSHOT"
}
subprojects {
apply {
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.kotlin.kapt")
plugin("org.jetbrains.kotlin.plugin.spring")
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
}
val developmentOnly by configurations.creating
configurations.runtimeClasspath.get().extendsFrom(developmentOnly)
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
api(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
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")
kapt("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
When building (./gradlew build) I'm getting this error:
> Task :adapters:kaptKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':adapters:kaptKotlin'.
> Could not resolve all files for configuration ':adapters:kapt'.
> Could not find org.springframework.boot:spring-boot-configuration-processor:.
Required by:
project :adapters
adapters:drivers:web is one of my subprojects and it is declared in settings.gradle.kts like this.
include("adapters:drivers:web")
PS: If I use annotationprocessor in place of kapt the build is successful. But I'm not sure if annotationprocessor can be used interchangeably with kapt since this will be a kotlin project.
kapt("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")
It seems kapt doesn't under the dependencies version management..
There is no repositories{} section is defined for you subprojects.
subprojects {
...
repositories {
mavenCentral()
}
}
I have a Kotlin Multiplatform project and I am trying to add Spring Boot to my Gradle dependencies. When a project is generated from the Spring Initializr it creates the developmentOnly dependency configuration as seen below. It also creates the testImplementation dependency configuration.
The first build.gradle.kts below is my attempt at transferring these to a multiplatform project, which so far hasn't worked. I have marked the lines that have problems with comments, they are towards the bottom of the file. Afterward, I have put a normal Spring Boot build.gradle.kts for comparison.
How can these be put into a multiplatform project? Or, if they can't be added for some reason, set up the configuration in such a way that the same result is achieved.
plugins {
id("org.springframework.boot") version "2.2.4.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("multiplatform") version "1.3.70-eap-184"
kotlin("plugin.spring") version "1.3.70-eap-184"
kotlin("plugin.jpa") version "1.3.70-eap-184"
}
group = "com.test"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_13
java.targetCompatibility = JavaVersion.VERSION_13
repositories {
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-dev/") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-js-wrappers") }
mavenCentral()
jcenter()
}
kotlin {
jvm()
js {
browser()
}
}
kotlin.sourceSets["jsMain"].dependencies {
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains:kotlin-react:16.9.0-pre.91-kotlin-1.3.61")
implementation("org.jetbrains:kotlin-react-dom:16.9.0-pre.91-kotlin-1.3.61")
implementation(npm("react", "16.12.0"))
implementation(npm("react-dom", "16.12.0"))
implementation("org.jetbrains:kotlin-styled:1.0.0-pre.91-kotlin-1.3.61")
implementation(npm("styled-components", "5.0.1"))
implementation(npm("inline-style-prefixer", "5.1.1"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3")
}
//The problems begin here
val developmentOnly by configurations.creating
configurations {
runtimeClasspath { //can't resolve runtimeClasspath
extendsFrom(developmentOnly) //can't resolve extendsFrom
}
}
kotlin.sourceSets["jvmMain"].dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
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("org.springframework.session:spring-session-core")
developmentOnly("org.springframework.boot:spring-boot-devtools") //error because of above where developmentOnly is defined
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test") { //can't resolve testImplementation
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("org.springframework.security:spring-security-test") //can't resolve testImplementation
}
Normal build.gradle.kts with Spring Boot (no issues)
plugins {
id("org.springframework.boot") version "2.2.4.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
war
kotlin("jvm") version "1.3.61"
kotlin("plugin.spring") version "1.3.61"
kotlin("plugin.jpa") version "1.3.61"
}
group = "com.test"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
}
repositories {
mavenCentral()
}
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")
runtimeOnly("com.microsoft.sqlserver:mssql-jdbc")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
I am trying to add the springboot buildInfo plugin to my build.gradle.kts so I can generate the build-info.properties file and expose the build info (i.e. app version) via the /actuator/info endpoint. However, I keep getting the following error when I add the buildInfo plugin:
Unresolved reference: springBoot
I've been referencing the following Spring documentation, but it just says to simply add the plugin and build.
Am I placing the plugin in the right spot in my gradle file? Do I need another dependency or plugin reference to get this working?
Here is what the main part of my build.gradle.kts looks like:
group = "com.walmart.muse.core-kt"
version = getLatestTagVersion()
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
plugins {
id("org.springframework.boot") version "2.2.0.RELEASE" apply false
kotlin("jvm") version "1.3.50"
kotlin("plugin.spring") version "1.3.50"
kotlin("plugin.jpa") version "1.3.50"
kotlin("plugin.allopen") version "1.3.50"
}
// This little code block is what is causing the error.
// I want to use it to get buid-info.properties so I can hit `/actuator/info`
// to expose my build info, but this isn't working :(
springBoot {
buildInfo()
}
allprojects {
repositories {
maven(url = "https://my-company's-repository.com") // edited for privacy
}
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "java")
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.jetbrains.kotlin.plugin.allopen")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
apply(plugin = "org.jetbrains.kotlin.plugin.jpa")
apply(plugin = "kotlin-spring")
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.apache.logging.log4j:log4j-api-kotlin:1.0.0")
implementation("io.springfox:springfox-swagger2:2.7.0")
implementation("io.springfox:springfox-swagger-ui:2.7.0")
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")
implementation("com.google.code.gson:gson:2.8.4")
runtimeOnly("mysql:mysql-connector-java:5.1.6")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
allOpen {
annotation("javax.persistence.Entity")
annotation("javax.persistence.Embeddable")
annotation("javax.persistence.MappedSuperclass")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
Reason is, that you used apply and as statted by gradle doc https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin_using_standard_api now gradle-kotlin-dsl can't use type safe accessors.
Instead of
springBoot {
buildInfo()
}
in your build.gradle.kts you have to use
configure<org.springframework.boot.gradle.dsl.SpringBootExtension> {
buildInfo()
}
I am working on a reactive spring boot api server. I first wanted to use MVC pattern, but I thought reactor would be a good idea.
So I have deleted all spring dependencies on MVC (I believe).
But spring keeps complaining that I can't use #EnableWebMvc along #EnableWebFlux.
Following is my error log
Caused by: java.lang.IllegalStateException: The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, e.g. via #EnableWebMvc and #EnableWebFlux, in the same application.
What possibly could be the problem? I sure did updated my dependencies.
And following is my build.gradle.kts file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories {
mavenCentral()
}
dependencies {
"classpath"(group = "gradle.plugin.com.palantir.gradle.docker", name = "gradle-docker")
}
}
plugins {
kotlin("plugin.jpa") version "1.3.40"
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
id("com.palantir.docker") version "0.22.1"
kotlin("jvm") version "1.3.40"
kotlin("plugin.spring") version "1.3.40"
}
group = "com.mycompany"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
}
repositories {
mavenCentral()
maven(url = "https://repo.spring.io/snapshot")
maven(url = "https://repo.spring.io/milestone")
}
extra["springCloudVersion"] = "Greenwich.SR1"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
//reactor
implementation("io.projectreactor:reactor-core")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.data:spring-data-jdbc:1.0.0.r2dbc-SNAPSHOT")
implementation("org.springframework.data:spring-data-r2dbc:1.0.0.M1")
implementation("io.r2dbc:r2dbc-spi:1.0.0.M5")
implementation("io.r2dbc:r2dbc-postgresql:1.0.0.M6")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.springframework.batch:spring-batch-test")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
exclude(group = "junit", module = "junit")
}
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
mavenBom("io.projectreactor:reactor-bom:Bismuth-RELEASE")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
task<Copy>("unpack") {
dependsOn(tasks.getByName("bootJar"))
from(zipTree(tasks.getByName("bootJar").outputs.files.singleFile))
into("build/dependency")
}
I figured it out by deleting each dependencies I have.
The problem was
implementation("org.springframework.boot:spring-boot-starter-web")
After deleting this, It worked. Maybe above dependency has it's own dependencies on WebMvc but I'm not sure.