The project structure

The example project is a simple scheduler project that contains four submodules.

  • Job-common common module
  • Job-util utility class module
  • Job-scheduler Indicates the scheduling center module
  • Job-admin Scheduling management module

The inheritance relationship between modules is shown in the following figure

The parent project build. Gradle. KTS

Plugins define plug-ins that take effect in all projects. The configuration specified in subprojects takes effect in all subprojects, where Maven is borrowed from dependencyManagement and a BOM can be introduced to easily define the version information for most dependencies. Allprojects specifies the repository image information that allprojects depend on.

plugins {
    kotlin("jvm")
    java
    id("io.spring.dependency-management")

    kotlin("plugin.lombok")
    id("io.freefair.lombok")}allprojects {
    repositories {
        mavenLocal()
        maven { setUrl("https://maven.aliyun.com/repository/public") }
        maven { setUrl("https://maven.aliyun.com/repository/central") }
        maven { setUrl("https://maven.aliyun.com/repository/spring") }
        maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
        maven { setUrl("https://maven.aliyun.com/repository/apache-snapshots") }
        maven { setUrl("https://maven.aliyun.com/repository/google") }
        maven { setUrl("https://maven.aliyun.com/repository/releases") }
        maven { setUrl("https://maven.aliyun.com/repository/snapshots") }
        maven { setUrl("https://maven.aliyun.com/repository/grails-core") }
        maven { setUrl("https://maven.aliyun.com/repository/mapr-public") }
        maven { setUrl("https://maven.aliyun.com/repository/gradle-plugin") }
        maven { setUrl("https://maven.aliyun.com/repository/spring-plugin") }
        mavenCentral()
    }
}

subprojects {
    group = "com.peaksong"
    version = "0.0.1 - the SNAPSHOT"

    apply(plugin = "java")
    apply(plugin = "kotlin")
    apply(plugin = "io.spring.dependency-management")

    java.sourceCompatibility = JavaVersion.VERSION_1_8
    java.targetCompatibility = JavaVersion.VERSION_1_8


    dependencies {

        implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery")
        implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config")
        implementation("org.springframework.cloud:spring-cloud-starter-bootstrap")

        implementation("org.jetbrains.kotlin:kotlin-reflect")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
        implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
        runtimeOnly("org.postgresql:postgresql")
        testImplementation("org.springframework.boot:spring-boot-starter-test") {
            exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
        }

    }

    extra["springCloudAlibabaVersion"] = "2021.1"
    extra["springCloudVersion"] = "2020.0.3"
    extra["springBootVersion"] = "2.4.10"
    extra["kotlin.version"] = "1.5.21"

    dependencyManagement {

        imports {
            mavenBom("com.alibaba.cloud:spring-cloud-alibaba-dependencies:${property("springCloudAlibabaVersion")}")
            mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
            mavenBom("org.springframework.boot:spring-boot-dependencies:${property("springBootVersion")}")}dependencies {
            dependency("Io.net ty: netty - all: 4.1.67. The Final")
            dependency("Org. Jctools: jctools - core: 3.3.0")
            project(":job-util")
            project(":job-common")}}}Copy the code

The parent project Settings. Gradle. KTS

In this file, you define the name of the subproject, declare the common plug-ins used in the project in pluginManagement, specify the repository address list to download the plug-in, and include all modules.

rootProject.name = "scheduler"

pluginManagement {
    plugins {
        id("org.springframework.boot") version "2.4.2"    // Affecting springboot packaging generates bootJar tasks
        id("io.spring.dependency-management") version "1.0.10. RELEASE"  // Springboot is managed by default
        kotlin("jvm") version "1.5.31"
        kotlin("plugin.spring") version "1.5.31"
        kotlin("plugin.jpa") version "1.5.31"

        kotlin("plugin.lombok") version "1.5.31"
        id("io.freefair.lombok") version "5.3.0"
    }

    repositories {
        mavenLocal()
        maven{ setUrl("https://maven.aliyun.com/repository/gradle-plugin") }
        maven{ setUrl("https://maven.aliyun.com/repository/spring-plugin") }
        maven{ setUrl("https://maven.aliyun.com/repository/central") }
        maven{ setUrl("https://maven.aliyun.com/repository/public")}}}include(":job-util")
include(":job-common")
include(":job-scheduler")
include(":job-admin")
Copy the code

Subprojects build. Gradle. KTS

The job-common module is implemented (project(“:job-common”))

dependencies {
    implementation(project(":job-common"))
    implementation(project(":job-util"))
}

tasks.getByName<Test>("test") {
    useJUnitPlatform()
}
Copy the code

Subproject Settings. Gradle. KTS

The following uses the job-admin subproject configuration as an example

rootProject.name = "job-admin"
Copy the code

supplement

If there is a dependency version conflict, you can resolve it in the following ways.

Configurations. All {resolutionStrategy {force (" com. Google. Guava guava: 20.0 ")}}Copy the code

Eliminate some dependencies

configurations.all {
    exclude("log4j", "log4j")
}
Copy the code