gradle build配置说明

Last updated on November 22, 2024 pm

🧙 Questions

build.gradle 配置文件说明

☄️ Ideas

dependencies {

    // 子项目依赖
    api(project(':leo-security'))

    // 添加依赖
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

// 指定打包位置
tasks.withType(Jar) {
    destinationDirectory.dir("$rootDir/build")
}

bootJar {
    enabled true
}

jar {
    enabled false
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
    maven { url "https://plugins.gradle.org/m2/" }
}

tasks.named('test') {
    useJUnitPlatform()
}

// spring boot 打包需要这个
bootJar {
    enabled(true)
}

// jar依赖打包需要这个
jar {
    enabled(true)
}

//task docs() {
//    Process docs_process
//    try {
//        def pb = new ProcessBuilder()
//        pb.directory(projectDir)
//        pb.command("cmd.exe", "/c", "npm i docsify-cli -g && docsify serve docs")
//        docs_process = pb.start()
//        try (def reader = new BufferedReader(new InputStreamReader(docs_process.getInputStream(), StandardCharsets.UTF_8))) {
//            while (docs_process.isAlive()) {
//                while (reader.ready()) {
//                    println(reader.readLine())
//                }
//            }
//        }
//    } catch (Exception e) {
//        println("task docs has exception:" + e.getMessage())
//        if (docs_process != null) {
//            docs_process.destroyForcibly()
//        }
//    } finally {
//        println("kill task docs")
//        if (docs_process != null) {
//            docs_process.destroyForcibly()
//        }
//    }
//}

注意: gradle的子模块自定义任务名 最好不要重复,不然有可能会重复处罚
dependsOn 会运行上面的task
mustRunAfter 不会运行,里面的人物


gradle build配置说明
https://ispong.isxcode.com/spring/gradle/gradle build配置说明/
Author
ispong
Posted on
March 9, 2022
Licensed under