From 39e5ebc6ec3285b18f43a48e2b6a353e682fd45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Sun, 31 Jul 2022 19:39:37 +0800 Subject: [PATCH] feat($spring-boot-admin): migrate from Maven to Gradle --- gradle.properties | 6 +- .../build.gradle.kts | 77 ++++++++++++ .../spring-boot-admin-bootstrap/pom.xml | 113 ------------------ .../src/main/resources/application.yml | 59 ++++----- 4 files changed, 112 insertions(+), 143 deletions(-) delete mode 100644 spring-boot-admin/spring-boot-admin-bootstrap/pom.xml diff --git a/gradle.properties b/gradle.properties index 357769c2..77209af4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,7 +32,7 @@ temurinTag=17.0.3_7-jre gradleGitVersion=0.15.0 gradleVersionsPluginVersion=0.42.0 dockerHubRepositoryPrefix=docker.io/ijohnnymiller/ -springBootAdminStarterVersion=2.7.1 +springBootAdminStarterVersion=2.7.3 springDocVersion=1.6.9 logstashLogbackEncoderVersion=7.2 minioVersion=8.4.2 @@ -58,3 +58,7 @@ mafMisArtifactId=maf-mis # OSS Center constants ossCenterPort=8760 ossCenterArtifactId=oss-center + +# Spring Boot Admin constants +springBootAdminPort=8761 +springBootAdminArtifactId=spring-boot-admin diff --git a/spring-boot-admin/spring-boot-admin-bootstrap/build.gradle.kts b/spring-boot-admin/spring-boot-admin-bootstrap/build.gradle.kts index c067342d..d9ffad84 100644 --- a/spring-boot-admin/spring-boot-admin-bootstrap/build.gradle.kts +++ b/spring-boot-admin/spring-boot-admin-bootstrap/build.gradle.kts @@ -1 +1,78 @@ +@file:Suppress("UnstableApiUsage") + +import com.palantir.gradle.gitversion.VersionDetails +import groovy.lang.Closure +import org.springframework.boot.gradle.tasks.bundling.BootJar +import org.springframework.boot.gradle.tasks.run.BootRun +import java.time.LocalDateTime + description = "Muscle and Fitness Server :: Spring Boot Admin - Bootstrap" + +plugins { + id("com.google.cloud.tools.jib") +} + +val versionDetails: Closure by extra +val gitVersionDetails = versionDetails() + +dependencies { + // MAF dependencies + implementation(project(":spring-cloud-starter")){ + exclude("de.codecentric", "spring-boot-admin-starter-client") + } + val springBootAdminStarterVersion: String by project + implementation("de.codecentric:spring-boot-admin-starter-server:$springBootAdminStarterVersion") +} + +tasks.withType { + this.enabled = true + // archiveFileName = [baseName]-[gitHash]-[version]-[classifier].[extension] + this.archiveFileName.set("${archiveBaseName.get()}-${gitVersionDetails.gitHash}-${archiveVersion.get()}.${archiveExtension.get()}") + logger.info("Building Spring Boot executable jar: ${this.archiveFileName.get()}") +} + +tasks.withType { + if (project.hasProperty("jvmArgs")) { + val jvmArgsProperty = (project.properties["jvmArgs"] as String) + logger.info("jvmArgsProperty for the app [${project.name}] (before split): `$jvmArgsProperty`") + jvmArgs = jvmArgsProperty.split(Regex("\\s+")) + logger.info("allJvmArgs for the app [${project.name}] (after split): $allJvmArgs") + } +} + +// https://www.baeldung.com/spring-boot-auto-property-expansion +// https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/copy/build.gradle.kts +// https://www.tristanfarmer.dev/blog/gradle_property_expansion_spring_boot +tasks.withType { + // Only expand the file `application.yml` + filesMatching("**/application.yml") { + expand(project.properties) + } +} + +springBoot { + buildInfo() +} + +// https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin +jib { + pluginExtensions { + pluginExtension { + implementation = "com.google.cloud.tools.jib.gradle.extension.springboot.JibSpringBootExtension" + properties = mapOf("useDeprecatedExcludeDevtoolsOption" to "true") + } + } + val temurinTag: String by properties + from.image = "eclipse-temurin:${temurinTag}" + val dockerHubRepositoryPrefix: String by properties + val projectArtifactId: String by properties + val springBootAdminArtifactId: String by properties + to.image = "$dockerHubRepositoryPrefix$projectArtifactId.$springBootAdminArtifactId" + to.tags = setOf("${gitVersionDetails.gitHash}-${project.version}") + container.appRoot = "/$springBootAdminArtifactId" + val projectBuildSourceEncoding: String by properties + container.jvmFlags = listOf("-Dfile.encoding=$projectBuildSourceEncoding") + val springBootAdminPort: String by properties + container.ports = listOf(springBootAdminPort) + container.creationTime = LocalDateTime.now().toString() +} diff --git a/spring-boot-admin/spring-boot-admin-bootstrap/pom.xml b/spring-boot-admin/spring-boot-admin-bootstrap/pom.xml deleted file mode 100644 index cef62977..00000000 --- a/spring-boot-admin/spring-boot-admin-bootstrap/pom.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - 4.0.0 - - spring-boot-admin-bootstrap - Muscle and Fitness Server :: Spring Boot Admin - Bootstrap - - - com.jmsoftware.maf - spring-boot-admin - 0.0.9.1-SNAPSHOT - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - build-info - compile - - build-info - - - - - - - - com.google.cloud.tools - jib-maven-plugin - ${jib-maven-plugin.version} - - - com.google.cloud.tools - jib-spring-boot-extension-maven - ${jib-spring-boot-extension-maven.version} - - - - - - - buildAndPushDockerImagePhase - install - - build - - - - - - - eclipse-temurin:${temurin.tag} - - - docker.io/ijohnnymiller/${project.baseArtifactId}.${project.parent.artifactId} - - - ${git.commit.id.abbrev}-${project.version} - - - - - /${project.parent.artifactId} - - -Dfile.encoding=${project.build.sourceEncoding} - - - ${spring-boot-admin.port} - - USE_CURRENT_TIMESTAMP - - - - - com.google.cloud.tools.jib.maven.extension.springboot.JibSpringBootExtension - - - true - - - - - - - - - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.3 - - - - diff --git a/spring-boot-admin/spring-boot-admin-bootstrap/src/main/resources/application.yml b/spring-boot-admin/spring-boot-admin-bootstrap/src/main/resources/application.yml index bcab891d..f5856905 100644 --- a/spring-boot-admin/spring-boot-admin-bootstrap/src/main/resources/application.yml +++ b/spring-boot-admin/spring-boot-admin-bootstrap/src/main/resources/application.yml @@ -1,7 +1,7 @@ server: - port: @spring-boot-admin.port@ + port: ${springBootAdminPort} tomcat: - uri-encoding: @project.build.sourceEncoding@ + uri-encoding: ${projectBuildSourceEncoding} shutdown: GRACEFUL servlet: context-path: @@ -13,11 +13,11 @@ spring: ignored-services: - "consul" application: - name: @project.parent.artifactId@ + name: ${springBootAdminArtifactId} profiles: - active: @environment@ + active: ${environment} config: - import: consul:${spring.cloud.consul.host}:${spring.cloud.consul.port} + import: consul:\${spring.cloud.consul.host}:\${spring.cloud.consul.port} cloud: # https://docs.spring.io/spring-cloud-consul/docs/current/reference/html/index.html#spring-cloud-consul-config consul: @@ -34,38 +34,39 @@ spring: delay: 1000 prefixes: - config + - shardingsphere discovery: register: true - instance-id: ${spring.application.name}-${spring.cloud.client.hostname}-${vcap.application.instance_id:${spring.application.instance_id:${random.value}}} - service-name: ${spring.application.name} - port: ${server.port} + instance-id: \${spring.application.name}-\${spring.cloud.client.hostname}-\${vcap.application.instance_id:\${spring.application.instance_id:\${random.value}}} + service-name: \${spring.application.name} + port: \${server.port} prefer-ip-address: true - ip-address: ${spring.cloud.client.ip-address} + ip-address: \${spring.cloud.client.ip-address} health-check-critical-timeout: 15s logging: - config: classpath:logback-configuration/logback-${spring.profiles.active}.xml + config: classpath:logback-configuration/logback-\${spring.profiles.active}.xml maf: project-properties: - base-package: @project.groupId@ - context-path: ${server.servlet.context-path} - group-id: @project.groupId@ - project-parent-artifact-id: @project.parent.artifactId@ - project-artifact-id: @project.artifactId@ - version: @project.version@ - description: @project.description@ - jdk-version: @java.version@ - environment: ${spring.profiles.active} - url: @project.url@ - inception-year: @inceptionYear@ - organization-name: @project.organization.name@ - organization-url: @project.organization.url@ - issue-management-system: @project.issueManagement.system@ - issue-management-url: @project.issueManagement.url@ - developer-name: @developerName@ - developer-email: @developerEmail@ - developer-url: @developerUrl@ + base-package: ${projectGroupId} + context-path: \${server.servlet.context-path} + group-id: ${projectGroupId} + project-parent-artifact-id: ${projectArtifactId} + project-artifact-id: ${springBootAdminArtifactId} + version: ${projectVersion} + description: "${description}" + jdk-version: ${javaVersion} + environment: \${spring.profiles.active} + url: ${projectUrl} + inception-year: ${inceptionYear} + organization-name: ${projectOrganizationName} + organization-url: ${projectOrganizationUrl} + issue-management-system: ${projectIssueManagementSystem} + issue-management-url: ${projectIssueManagementUrl} + developer-name: ${developerName} + developer-email: ${developerEmail} + developer-url: ${developerUrl} configuration: ignored-url: pattern: @@ -77,4 +78,4 @@ maf: - "/*/v2/api-docs/**" - "/webjars/**" - "/doc.html" - included-package-for-http-api-scan: ${maf.project-properties.base-package} + included-package-for-http-api-scan: \${maf.project-properties.base-package}