Skip to content

Commit

Permalink
Convert to multi-module project
Browse files Browse the repository at this point in the history
  • Loading branch information
matchilling committed Jun 19, 2024
1 parent 9527e2e commit 3627abb
Show file tree
Hide file tree
Showing 94 changed files with 193 additions and 3,300 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
JAVA_VERSION: 21

jobs:
deploy:
deploy-web:
runs-on: [ ubuntu-latest ]
steps:
- name: Checkout code
Expand All @@ -37,7 +37,7 @@ jobs:
username: _

- name: Push image to Heroku registry
run: ./gradlew dockerPushHerokuProduction
run: ./gradlew :chucknorris-web:dockerPushHerokuProduction

- name: Trigger release
shell: bash
Expand Down
125 changes: 36 additions & 89 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,98 +1,45 @@
plugins {
id 'com.diffplug.spotless' version '7.0.0.BETA1'
id 'com.palantir.docker' version '0.36.0'
id 'io.spring.dependency-management' version '1.1.5'
id 'java'
id 'org.springframework.boot' version '2.7.18'
import org.gradle.api.tasks.testing.logging.TestLogEvent

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.diffplug.spotless:spotless-plugin-gradle:${Version.SPOTLESS}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${Version.SPRING_BOOT}")
}
}

def gitRev = { ->
def stdout = new ByteArrayOutputStream()
version = Git.commitHash()

exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
subprojects { Project project ->
apply plugin: 'com.diffplug.spotless'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'

return stdout.toString().trim()
}

String appName = "api"
String appVer = gitRev()

group = "io.chucknorris"
version = appVer
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
}

// versions
def lombokVersion = "1.18.30"
sourceCompatibility = 17
targetCompatibility = 17
version Git.commitHash()

dependencies {
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
dependencyManagement {
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${Version.SPRING_BOOT}") }
}

implementation "com.amazonaws:aws-java-sdk:1.11.561"
implementation "com.fasterxml.jackson.core:jackson-core:2.17.1"
implementation "com.rometools:rome:1.12.0"
implementation "com.vladmihalcea:hibernate-types-52:2.4.0"
implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0"
implementation "org.hibernate:hibernate-validator:6.0.16.Final"
implementation "org.postgresql:postgresql:42.2.9"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation 'com.google.guava:guava:33.2.1-jre'

testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation 'junit:junit:4.12'
}
repositories {
mavenCentral()
}

tasks {
bootJar {
manifest.attributes(
'Multi-Release': 'true'
)
tasks.withType(Test) {
useJUnitPlatform()

archiveBaseName.set(appName)
archiveVersion.set(appVer)
testLogging {
events TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED
}
}

if (project.hasProperty("archiveName")) {
archiveFileName.set(project.properties["archiveName"] as String)
}
}

docker {
dependsOn bootJar

def imageName = "${project.properties.group}/${appName}"
name = "${imageName}:latest"

tag("current", "${imageName}:${appVer}")
tag("latest", "${imageName}:latest")
tag("herokuProduction", "registry.heroku.com/chucky/web")

dockerfile file("${projectDir}/src/main/docker/Dockerfile")
files tasks.bootJar.outputs
buildArgs([JAR_FILE: bootJar.getArchiveFileName().get()])
}

springBoot {
buildInfo {
properties {
artifact = "${appName}-${appVer}.jar"
version = appVer
name = appName
}
}
}

spotless {
java {
googleJavaFormat()
}
}
}
spotless {
java {
googleJavaFormat()
}
}
}
70 changes: 70 additions & 0 deletions buildSrc/src/main/groovy/Git.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import org.gradle.api.GradleException

class Git {

private static final VERSION_2 = "git version 2"

static String branch() throws GradleException {
def gitBranch = execute('git rev-parse --abbrev-ref HEAD')

if (gitBranch == null || gitBranch.empty) {
throw new GradleException('Could not determine Git branch name')
}

return gitBranch.replace("/", "-")
}

static int commitCount() {
return execute('git rev-list --count HEAD').toInteger()
}

static int commitDateUnix() {
return execute(
"git show -s --format=%ct ${commitHash()}"
).toInteger()
}

static String commitHash() {
return execute('git rev-parse HEAD')
}

static String commitHashShort() {
return execute('git rev-parse --short HEAD').substring(0, 7)
}

static String remoteOriginUrl() {
return execute('git config --get remote.origin.url')
}

static void writePropertiesTo(pathname) {
def properties = new Properties()

properties.setProperty('git.branch', branch())
properties.setProperty('git.commit_count', commitCount().toString())
properties.setProperty('git.commit_date_unix', commitDateUnix().toString())
properties.setProperty('git.commit_long', commitHash())
properties.setProperty('git.commit_short', commitHashShort())
properties.setProperty('git.remote_origin_url', remoteOriginUrl())

def file = new File(pathname)
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs()
}

file.withWriter('UTF-8') {
properties.each { key, value -> it.writeLine("$key = $value") }
}
}

static boolean isAvailable() {
try {
return execute("git --version").startsWith(VERSION_2)
} catch (ignored) {
return false
}
}

private static String execute(String command) {
return command.execute().in.text.trim()
}
}
4 changes: 4 additions & 0 deletions buildSrc/src/main/groovy/Version.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface Version {
public static final String SPRING_BOOT = '2.7.18'
public static final String SPOTLESS = '7.0.0.BETA1'
}
69 changes: 69 additions & 0 deletions chucknorris-web/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id "com.palantir.docker" version "0.36.0"
id 'org.springframework.boot'
}

repositories {
mavenCentral()
}

// versions
def lombokVersion = "1.18.30"

dependencies {
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

implementation "com.amazonaws:aws-java-sdk:1.11.561"
implementation "com.fasterxml.jackson.core:jackson-core:2.17.1"
implementation "com.rometools:rome:1.12.0"
implementation "com.vladmihalcea:hibernate-types-52:2.4.0"
implementation "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0"
implementation "org.hibernate:hibernate-validator:6.0.16.Final"
implementation "org.postgresql:postgresql:42.2.9"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "com.google.guava:guava:33.2.1-jre"

testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "junit:junit:4.12"
}

tasks {
bootJar {
manifest.attributes("Multi-Release": "true")

archiveBaseName.set(project.name)
archiveVersion.set(project.version)

if (project.hasProperty("archiveName")) {
archiveFileName.set(project.properties["archiveName"] as String)
}
}

docker {
dependsOn bootJar

def imageName = "${project.properties.group}/${project.name}"
name = "${imageName}:latest"

tag("current", "${imageName}:${project.version}")
tag("latest", "${imageName}:latest")
tag("herokuProduction", "registry.heroku.com/chucky/web")

dockerfile file("${projectDir}/src/main/docker/Dockerfile")
files tasks.bootJar.outputs
buildArgs([JAR_FILE: bootJar.getArchiveFileName().get()])
}

springBoot {
buildInfo {
properties {
artifact = "${project.name}-${project.version}.jar"
version = project.version
name = project.name
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3627abb

Please sign in to comment.