This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
141 lines (121 loc) · 6.24 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
plugins {
id 'java'
// Spring Boot Plugin - Reacting to the Java Plugin
// More info: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#reacting-to-other-plugins.java
// When Gradle’s java plugin is applied to a project, the Spring Boot plugin:
// * Creates a BootJar task named bootJar that will create an executable, fat jar for the project. The jar will contain everything on the runtime classpath of the main source set; classes are packaged in BOOT-INF/classes and jars are packaged in BOOT-INF/lib
// * Configures the assemble task to depend on the bootJar task.
// * Configures the jar task to use plain as the convention for its archive classifier.
// * Creates a BootBuildImage task named bootBuildImage that will create a OCI image using a buildpack.
// * Creates a BootRun task named bootRun that can be used to run your application.
// * Creates a configuration named bootArchives that contains the artifact produced by the bootJar task.
// * Creates a configuration named developmentOnly for dependencies that are only required at development time, such as Spring Boot’s Devtools, and should not be packaged in executable jars and wars.
// * Creates a configuration named productionRuntimeClasspath. It is equivalent to runtimeClasspath minus any dependencies that only appear in the developmentOnly configuration.
// * Configures any JavaCompile tasks with no configured encoding to use UTF-8.
// * Configures any JavaCompile tasks to use the -parameters compiler argument.
id 'org.springframework.boot' version "${springBootVersion}" apply false
id 'io.spring.dependency-management' version "${springDepMgmtVersion}"
// Source: https://github.com/Netflix/dgs-codegen
// Guide: https://netflix.github.io/dgs/generating-code-from-schema/
id "com.netflix.dgs.codegen" version "${dgsCodeGenPluginVersion}" apply false
}
var projectVersion = rootProject.file('version.txt').text.trim()
var shortVersion = projectVersion.replaceAll("-SNAPSHOT", "")
var dateTime = new Date();
print "\n${project.name} [v${projectVersion}] --- Build time: ${dateTime}\n\n"
// https://spring.io/guides/gs/multi-module/
// Took a lot of guidance about multi-module builds from: https://reflectoring.io/spring-boot-gradle-multi-module/
subprojects {
group = 'com.mikeoertli.sample.mrs'
version = projectVersion
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
// more info: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter'
implementation "org.apache.commons:commons-lang3:${apacheCommonsLang3Version}"
testImplementation "org.assertj:assertj-core:${assertJVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation "org.mockito:mockito-junit-jupiter:${mockitoVersion}"
}
test {
useJUnitPlatform()
}
// https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image.customization
// https://spring.io/guides/gs/spring-boot-docker/
// https://codingnconcepts.com/spring-boot/deployment-of-microservices-using-docker-and-jenkins/
tasks.named('bootBuildImage') {
// These are the modules for which we do not want to build an image
def noDockerModules = [ 'kafka-adapter', 'db-adapter' , 'mongo-adapter', 'model', 'common' ]
if (noDockerModules.contains(project.name)) {
enabled = false
} else
{
// Create two tags, one with the current version and one with 'latest'
imageName = 'mikeoertli/mike-rowe-service-' + project.name
tags=[imageName + ':' + project.version, imageName + ':latest']
}
}
tasks.named('bootJar') {
// These are the modules for which we do not want to build a boot jar
def noBootJarModules = [ 'kafka-adapter', 'db-adapter' , 'mongo-adapter', 'model', 'common' ]
enabled = noBootJarModules.contains(project.name)
}
springBoot {
// Idea from: https://tomgregory.com/unleashing-the-spring-boot-gradle-plugin/
// Also seen here: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#integrating-with-actuator
// With app running (`./gradlew bootRun`) you can see metadata build info at:
// http://localhost:8080/actuator/info
buildInfo()
}
task sourcesJar(type: Jar, dependsOn:classes) {
archiveClassifier.set('sources')
from sourceSets.main.allJava
}
task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
from javadoc
}
artifacts {
archives sourcesJar
archives javadocJar
}
// Debug task to print out the source (srcSet) for each task, the output directory for compiled code, and the compile classpath.
// This isn't a replacement for a gradle dependencyInsight etc, but is a helpful quick tool.
task printSourceSetInformation() {
doLast {
sourceSets.each { srcSet ->
println "[" + srcSet.name + "]"
print " --> Source directories: " + srcSet.allJava.srcDirs + "\n"
print " --> Output directories: " + srcSet.output.classesDirs.files + "\n"
print " --> Compile classpath:\n"
srcSet.compileClasspath.files.each {
print " " + it.path + "\n"
}
println ""
}
}
}
}
//Show additional details on deprecation warnings
//allprojects {
// gradle.projectsEvaluated {
// tasks.withType(JavaCompile) {
// options.compilerArgs << "-Xlint:deprecation"
// }
// }
//}