魅力峰值

导航

gradle脱坑


1、gradle可以引用Java环境

例:

import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.time.LocalDateTime



task buildLog {
    dependsOn copyFiles
    doLast {
        StringBuilder sb = new StringBuilder(1024)
        sb.append("Build Date     : ").append(LocalDateTime.now()).append('\n')

        sb.append("Build Tools    : ").append("Gradle(v").append(gradle.gradleVersion).append(")").append('\n')

        sb.append("Git Branch     : ").append(getGitBranchName()) append('\n')

        getGitLastCommit().split('\n').each { e ->
            String s = e.trim()
            if (s.length() > 0) {
                sb.append("  => ").append(s).append('\n')
            }
        }

        sb.append("Dependency Libs: ").append('\n')
        configurations.runtimeClasspath.files.sort({ e -> e.name }).each { e ->
            sb.append("  => ").append(e.name).append(dataSize(e.length())).append('\n')
        }

        String buildInfo = sb.toString()

        println buildInfo

        Files.write(Paths.get(file("build/app/" + project.name + "/build.log").absolutePath)
                , buildInfo.getBytes(StandardCharsets.UTF_8))
    }
}

  2、gradle分多模块,多模块无效

         

    jar{
        enabled = true
    }

  

     3、gradle7.0之后,compile无法使用,切换成 api

posted on 2022-09-29 16:27  魅力峰值  阅读(33)  评论(0编辑  收藏  举报