-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
169 lines (140 loc) · 5.51 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import groovy.transform.Memoized
import java.text.SimpleDateFormat
plugins {
id 'com.diffplug.spotless' version '6.25.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'application'
}
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)) {
throw new GradleException("Java 21 or later is required to build Portfolio Manager.\n" +
" Detected version ${JavaVersion.current()}")
}
group = 'com.rodion.adelie'
defaultTasks 'build', 'javadoc'
def buildAliases = ['dev': [
'spotlessApply',
'build',
'javadoc'
]]
def expandedTaskList = []
gradle.startParameter.taskNames.each {
expandedTaskList << (buildAliases[it] ? buildAliases[it] : it)
}
gradle.startParameter.taskNames = expandedTaskList.flatten()
tasks.register("dev")
allprojects {
apply plugin: 'java-library'
apply plugin: 'io.spring.dependency-management'
apply from: "${rootDir}/gradle/versions.gradle"
version = calculateVersion()
repositories {
mavenCentral()
}
apply plugin: 'com.diffplug.spotless'
spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
toggleOffOn()
googleJavaFormat(googleJavaFormat)
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
javadoc {
options.addStringOption('Xdoclint:all,-missing', '-quiet')
options.addStringOption('Xmaxerrs','65535')
options.addStringOption('Xmaxwarns','65535')
options.addStringOption('Xwerror', '-html5')
options.encoding = 'UTF-8'
}
}
jar { enabled = false }
dependencies {
implementation project(':adelie')
}
application {
mainClass = 'com.rodion.adelie.Adelie'
}
applicationDefaultJvmArgs = [
// ADELIE_HOME is replaced by a doFirst block in the run task.
'-Dadelie.home=ADELIE_HOME',
// We shutdown log4j ourselves, as otherwise this shutdown hook runs before our own and whatever
// happens during shutdown is not logged.
'-Dlog4j.shutdownHookEnabled=false',
// Disable JNI lookups in log4j messages to improve security
'-Dlog4j2.formatMsgNoLookups=true',
]
def buildDirectory = layout.buildDirectory
run {
args project.hasProperty("adelie.run.args") ? project.property("adelie.run.args").toString().split("\\s+") : []
applicationDefaultJvmArgs = applicationDefaultJvmArgs.collect {
it.replace('ADELIE_HOME', buildDirectory.dir("adelie").get().asFile.toString())
}
}
startScripts {
defaultJvmOpts = applicationDefaultJvmArgs + [
"-XX:G1ConcRefinementThreads=2",
"-XX:G1HeapWastePercent=15",
"-XX:MaxGCPauseMillis=100"
]
unixStartScriptGenerator.template = resources.text.fromFile("${projectDir}/adelie/src/main/scripts/unixStartScript.txt")
doLast { tweakStartScript(startScripts) }
}
@Memoized
def calculateVersion() {
// Regex pattern for basic calendar versioning, with provision to omit patch rev
def calVerPattern = ~/\d+\.\d+(\.\d+)?(-.*)?/
if (project.hasProperty('version') && (project.version =~ calVerPattern)) {
return "${project.version}"
} else {
// If no version is supplied or it doesn't match the semantic versioning, calculate from git
println("Generating project version as supplied is version not semver: ${project.version}")
def gitDetails = getGitCommitDetails(10) // Adjust length as needed
return "${gitDetails.date}-develop-${gitDetails.hash}"
}
}
def getGitCommitDetails(length = 8) {
try {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
gitFolder = file(gitFolder).text.substring(length).trim() + "/"
}
def takeFromHash = length
def head = new File(gitFolder + "HEAD").text.split(":")
def isCommit = head.length == 1
def commitHash, refHeadFile
if (isCommit) {
commitHash = head[0].trim().take(takeFromHash)
refHeadFile = new File(gitFolder + "HEAD")
} else {
refHeadFile = new File(gitFolder + head[1].trim())
commitHash = refHeadFile.text.trim().take(takeFromHash)
}
// Use head file modification time as a proxy for the build date
def lastModified = new Date(refHeadFile.lastModified())
// Format the date as "yy.M" (e.g. 24.3 for March 2024)
def formattedDate = new SimpleDateFormat("yy.M").format(lastModified)
return [hash: commitHash, date: formattedDate]
} catch (Exception e) {
logger.info('Could not calculate git commit details, using defaults (run with --info for stacktrace)')
logger.info('Error retrieving git commit details', e)
return [hash: "xxxxxxxx", date: "00.0"]
}
}
def tweakStartScript(createScriptTask) {
def shortenWindowsClasspath = { line ->
line.replaceAll(/^set CLASSPATH=.*$/, "set CLASSPATH=%APP_HOME%/lib/*")
}
createScriptTask.unixScript.text = createScriptTask.unixScript.text.replace('ADELIE_HOME', '\$APP_HOME')
createScriptTask.windowsScript.text = createScriptTask.windowsScript.text.replace('ADELIE_HOME', '%~dp0..')
// Prevent the error originating from the 8191 chars limit on Windows
createScriptTask.windowsScript.text =
createScriptTask.windowsScript
.readLines()
.collect(shortenWindowsClasspath)
.join('\r\n')
}