-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
332 lines (264 loc) · 8.25 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.3/userguide/tutorial_java_projects.html
*/
buildscript {
repositories {
mavenCentral()
maven {
setUrl("https://plugins.gradle.org/m2/")
}
}
}
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the gradle plugin to add support for Gradle
id 'groovy'
// Apply the application plugin to add support for building a CLI application.
id 'application'
// JavaFX
id "org.openjfx.javafxplugin" version "0.1.0"
// Spotless for code formatting
id "com.diffplug.spotless" version "6.25.0"
// Code coverage
id 'jacoco'
id "org.jetbrains.kotlin.jvm" version "1.9.24"
// Linter
id 'io.gitlab.arturbosch.detekt' version '1.23.7'
}
// 変数定義
// ソースコードに埋め込むコミットハッシュ値。デフォルト値はdevで、CIでのビルド時
// に値を差し替える。
def commitHash = 'dev'
def VERSION_SOURCE_FILE = 'application.properties'
def SRC_FILE = 'template/' + VERSION_SOURCE_FILE
def DST_DIR = 'src/main/resources/com/jiro4989/tkfm/properties'
def DST_FILE = DST_DIR + '/' + VERSION_SOURCE_FILE
def LIB_DIR = './lib'
def APP_MODS = [
'javafx.base',
'javafx.controls',
'javafx.swing',
'javafx.graphics',
'javafx.fxml',
]
def jmodsDir = './jmods/javafx-jmods-11.0.2'
def CUSTOM_JRE_DIR = 'jre'
repositories {
mavenCentral()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:33.3.0-jre'
// Use JUnit test framework
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.11.0'
testImplementation "org.testfx:testfx-junit5:4.0.18"
// JavaFX
implementation "org.openjfx:javafx-fxml:22.0.2"
implementation "org.openjfx:javafx-base:22.0.2"
implementation "org.openjfx:javafx-controls:22.0.2"
implementation "org.openjfx:javafx-graphics:22.0.2"
implementation "org.openjfx:javafx-swing:22.0.2"
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
}
sourceCompatibility = 17
targetCompatibility = 17
application {
// Define the main class for the application.
getMainClass().set('com.jiro4989.tkfm.Main')
}
test {
useJUnitPlatform()
jacoco {
destinationFile = file("${buildDir}/jacoco/test.exec")
}
}
compileJava {
options.encoding = 'UTF-8'
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "17"
}
javafx {
modules = [
'javafx.controls',
'javafx.fxml',
'javafx.swing'
]
}
jar {
manifest {
attributes 'Main-Class': 'com.jiro4989.tkfm.Main'
}
archiveBaseName = 'tkfm'
from {
configurations.compileClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.register('junitPlatformJacocoReport', JacocoReport) {
group = "Verification"
description = "Jacocoを使ってテストのレポートを取得する"
sourceSets sourceSets.main
executionData test
}
jacocoTestReport {
reports {
xml.required = true
html.required = true
}
}
spotless {
java {
googleJavaFormat('1.13.0')
trimTrailingWhitespace()
endWithNewline()
removeUnusedImports()
}
kotlin {
ktfmt('0.15')
}
groovyGradle {
target '*.gradle'
greclipse().configFile("$rootDir/greclipse.properties")
}
}
detekt {
// Version of Detekt that will be used. When unspecified the latest detekt
// version found will be used. Override to stay on the same version.
toolVersion = "1.19.0"
// Define the detekt configuration(s) you want to use.
// Defaults to the default detekt configuration.
config = files("detekt.yml")
//
// // Specifying a baseline file. All findings stored in this file in subsequent runs of detekt.
// baseline = file("path/to/baseline.xml")
// Disables all default detekt rulesets and will only run detekt with custom rules
// defined in plugins passed in with `detektPlugins` configuration. `false` by default.
disableDefaultRuleSets = false
// Adds debug output during task execution. `false` by default.
debug = false
// If set to `true` the build does not fail when the
// maxIssues count was reached. Defaults to `false`.
ignoreFailures = false
// Android: Don't create tasks for the specified build types (e.g. "release")
ignoredBuildTypes = ["release"]
// Android: Don't create tasks for the specified build flavor (e.g. "production")
ignoredFlavors = ["production"]
// Android: Don't create tasks for the specified build variants (e.g. "productionRelease")
ignoredVariants = ["productionRelease"]
// Specify the base path for file paths in the formatted reports.
// If not set, all file paths reported will be absolute file path.
basePath = projectDir
}
tasks.named("detekt").configure {
dependsOn 'spotlessApply'
reports {
xml.required.set(false)
sarif.required.set(false)
html.required.set(true)
html.outputLocation.set(file("build/reports/detekt.html"))
txt.required.set(true)
txt.outputLocation.set(file("build/reports/detekt.txt"))
}
}
version = '0.0.0-SNAPSHOT'
if (project.hasProperty('CI_VERSION')) {
version = CI_VERSION
}
if (project.hasProperty('CI_COMMIT_HASH')) {
commitHash = CI_COMMIT_HASH
}
// Version.javaにバージョン番号とコミットハッシュを埋め込んでコピーする。
//
// 環境変数を指定せずにビルドするとdevがデフォルトでセットされる。
// CIでのビルド時にはタグ番号とコミットハッシュが埋め込まれる。
// こうすることでタグ番号の二重管理を防ぐことができる。
tasks.register('versionSet', Copy) {
group = "Build"
description = "ソースコードにビルド時のタグバージョンとコミットハッシュ値を埋め込む"
from SRC_FILE
into DST_DIR
expand(version: version, commitHash: commitHash)
doFirst {
delete DST_FILE
}
}
tasks.register('cleanDependencies') {
group = "Build"
description = "依存ライブラリを削除する"
doLast {
delete LIB_DIR
}
}
// dependenciesで取得したjarファイルをlib配下にコピーする。
//
// runAppで実行するときにライブラリのパスを指定するために使用する。
tasks.register('dumpDependencies') {
group = "Build"
description = "依存ライブラリjarをlib配下にコピーする"
doLast {
configurations.compileClasspath.each {
def jarFile = it.absolutePath
copy {
from jarFile
into LIB_DIR
}
}
}
}
tasks.register('runApp', Exec) {
group = "Application"
description = "アプリケーションを起動する"
commandLine 'java',
'--module-path', LIB_DIR,
'--add-modules', APP_MODS.join(','),
'-jar', "build/libs/tkfm-${version}.jar"
}
if (project.hasProperty('CI_JMODS_DIR')) {
jmodsDir = CI_JMODS_DIR
}
tasks.register('cleanCustomJRE') {
group = "Build"
description = "生成したカスタムJREを削除する"
doLast {
delete CUSTOM_JRE_DIR
}
}
// カスタムJREを作成する。
tasks.register('jlink', Exec) {
group = "Build"
description = "jlinkを使ってカスタムJREを作成する"
commandLine 'jlink',
'--module-path', jmodsDir,
'--add-modules', APP_MODS.join(','),
'--compress=2',
'--output', CUSTOM_JRE_DIR
}
// 実行順序の明示
spotlessApply.dependsOn(['clean'])
versionSet.dependsOn(['spotlessApply'])
test.dependsOn('spotlessApply')
// detekt.dependsOn('spotlessApply')
processResources.dependsOn(['versionSet'])
compileJava.dependsOn(['processResources'])
compileKotlin.dependsOn(['processResources'])
jacocoTestReport.dependsOn(['test'])
dumpDependencies.dependsOn(['cleanDependencies'])
runApp.dependsOn(['dumpDependencies'])
jlink.dependsOn(['cleanCustomJRE'])