从此

Gradle Build 构建 & Maven Repositories & Artifacts - 知名开源项目库、仓库POM文件 | Jib Plugin

综合/最新

Kotlin变量声明:并非var而是 val k=v

Kotlin导入类:必须写在顶部 - import java.time.Instant 使用 - Instant.now().toString().replace(":", "_")

操作文件前判断是否存在:即Kotlin的三元表达式
  val txtFile=file("../../../../docs/cloud/project-123456.json")
  password = if (txtFile.exists()) txtFile.readText() else null

构建容器镜像

build.gradle.kts
plugins { application id("com.google.cloud.tools.jib") version "3.4.5" } jib{ from { // 打包后210MiB;默认 eclipse-temurin:21-jre;jlink 容器大小优化 - blog.csdn.net/zypqqgc/article/details/142070527 image = "eclipse-temurin:24-jre-alpine" } to { /* tags = mutableSetOf(Instant.now().toString().replace(":", "_")) image = "asia-east1-docker.pkg.dev/project-123456/temp-repo/new-tech" auth { username = "_json_key" val txtFile=file("../../../../docs/cloud/project-123456-8ad030ce3d3e.json") password = if (txtFile.exists()) txtFile.readText() else null } */ tags = mutableSetOf("new-tech-"+Instant.now().toString().replace(":", "_")) image = "dockerhubuser/private" // docker.io/dockerhubuser/private:new-tech-0.0.1b1 auth { username = "dockerhubuser" password = System.getenv("DOCKER_PASSWORD")?:"" // ALIYUN_DOCKER_PASSWORD } containerizingMode = "packaged" // jar包目标路径 /app/classpath/main-class.jar、/app/libs/jetty-server-12.0.16.jar } container { jvmFlags = mutableListOf("-XX:MaxRAMPercentage=95","-XX:+UseZGC","-XX:+CrashOnOutOfMemoryError") mainClass = application.mainClass.get() // 多个主类时才需指定 } }

知名项目库

MySQL Connector/J
implementation("com.mysql:mysql-connector-j:9.1.0")
Jakarta Servlet
compileOnly("jakarta.servlet:jakarta.servlet-api:6.1.0")
JSON Web Token (JWT)
implementation("com.auth0:java-jwt:4.4.0")
Spring Authorization Server
implementation("org.springframework.boot:spring-boot-starter-oauth2-authorization-server:3.4.1")
Google Cloud Libraries Bill of Materials (BOM)
implementation(platform("com.google.cloud:libraries-bom:26.53.0"))

其他