Skip to content

Commit

Permalink
feat($spring-boot-admin): migrate from Maven to Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Jul 31, 2022
1 parent 06ca634 commit 39e5ebc
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 143 deletions.
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
77 changes: 77 additions & 0 deletions spring-boot-admin/spring-boot-admin-bootstrap/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<VersionDetails> 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<BootJar> {
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<BootRun> {
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<ProcessResources> {
// 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()
}
113 changes: 0 additions & 113 deletions spring-boot-admin/spring-boot-admin-bootstrap/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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}

0 comments on commit 39e5ebc

Please sign in to comment.