gpt4 book ai didi

java - Gradle , Kotlin : How to add another spring boot project as a module dependency in intellij

转载 作者:行者123 更新时间:2023-12-03 05:37:17 28 4
gpt4 key购买 nike

我有两个 Spring Boot 项目

Project1 (Spring boot project)
|
|--build.gradle
|--settings.gradle
|--src/main/kotlin

Project2 (Spring boot project)
|
|--build.gradle
|--settings.gradle
|--src/main/kotlin

Project2 依赖于 Project1。有人可以告诉我如何添加此依赖项(例如修改 build.gradle 和 settings.gradle),以便这些项目可以正常工作。我已经尝试了很多资源,但没有运气来实现这一目标。

PS:Project1 和 Project2 都是 Spring Boot Kotlin 项目,它们单独工作正常。我想将 Project1 的某些功能重用到 Project2 中,但我无法做到。

此外,Project1 和 Project2 位于同一目录级别。

任何帮助将不胜感激。

最佳答案

根项目
作为第一步,您需要添加带有两个子项目的根项目。settings.gradle.kts

rootProject.name = "demo-root"

include(
"project1",
"project2"
)
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
base
kotlin("jvm") version "1.3.71" apply true
id("java-library")
id("org.springframework.boot") version "2.2.6.RELEASE" apply false
id("io.spring.dependency-management") version "1.0.9.RELEASE" apply false
id("org.jetbrains.kotlin.plugin.jpa") version "1.3.71" apply false
kotlin("plugin.spring") version "1.3.71" apply false
}

allprojects {
group = "com.dempcompany"
version = "0.0.1-SNAPSHOT"

repositories {
mavenCentral()
}

// apply {
// plugin("kotlin")
// }

tasks.withType<JavaCompile> {
sourceCompatibility = "13"
targetCompatibility = "13"
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "12"
}
}
}

subprojects {
// apply {
// plugin("io.spring.dependency-management")
// }
}

dependencies {
subprojects.forEach {
// Make the root project archives configuration depend on every subproject
archives(it)
}
}
项目1
然后为project1配置构建配置 project1/build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
base
kotlin("jvm") version "1.3.71" apply true
id("java-library")
id("org.springframework.boot") version "2.2.6.RELEASE" apply false
id("io.spring.dependency-management") version "1.0.9.RELEASE" apply false
id("org.jetbrains.kotlin.plugin.jpa") version "1.3.71" apply false
kotlin("plugin.spring") version "1.3.71" apply false
}

allprojects {
group = "com.democompany"
version = "0.0.1-SNAPSHOT"

repositories {
mavenCentral()
}

// apply {
// plugin("kotlin")
// }

tasks.withType<JavaCompile> {
sourceCompatibility = "13"
targetCompatibility = "13"
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "12"
}
}
}

subprojects {
// apply {
// plugin("io.spring.dependency-management")
// }
}

dependencies {
subprojects.forEach {
// Make the root project archives configuration depend on every subproject
archives(it)
}
}
project1/setting.gradle.kts
rootProject.name = "project1"
项目2
然后为project2配置构建配置 project2/build.gradle.kts
plugins {
id("org.springframework.boot")
id("io.spring.dependency-management")
kotlin("jvm")
kotlin("plugin.spring")
}

repositories {
mavenCentral()
maven("https://jitpack.io")
}

java.sourceCompatibility = JavaVersion.VERSION_13

dependencies {
/* Project modules */
implementation(project(":project1", "default"))

/* Spring Framework */
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")

/* Kotlin */
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
}
project2/settings.gradle.kts
rootProject.name = "project2"

关于java - Gradle , Kotlin : How to add another spring boot project as a module dependency in intellij,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55197672/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com