This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
263 lines (224 loc) · 8.31 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
/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
tasks:
bootRun - Spring Boot 起動
-> http://localhost:8080/
build - War ファイル作成
-> build/libs/template.war
jacocoReport - JaCoCo Code Coverage 起動
-> 先に test を起動
-> HTML report build/reports/jacoco/jacocoReport/html
-> XML repott build/reports/jacoco/jacocoReport/jacocoReport.xml (連携用)
uploadCoverageToCodacy - Codacy に Coverage 結果をアップロードする(JaCoCo の Coverage 結果をアップロード)。
-> 先に jacocoReport を起動
-> Codacy の API Token を設定しないとエラーになります。
-> ローカル : Windows CLI(set CODACY_PROJECT_TOKEN=Codacy のトークン)
-> Circle CI : Builds -> 対象プロジェクト -> Settings -> Environment Variables -> Add Variable
Name : CODACY_PROJECT_TOKEN
Value : Codacy のトークン(Codacy -> MyProjecys -> 対象プロジェクト選択 -> Settings -> Integrations -> Project API(Settings button click -> Project API Token が表示されます))
引数なし bootRun
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
jcenter() // gradle-versions-plugin で利用
maven { url "http://dl.bintray.com/typesafe/maven-releases" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
// https://github.com/ben-manes/gradle-versions-plugin
classpath("com.github.ben-manes:gradle-versions-plugin:0.14.0")
}
}
// 引数なしで起動した場合、bootRun
defaultTasks "bootRun"
/* ---------------------------
プラグインの定義
----------------------------*/
apply plugin: 'java'
apply plugin: 'eclipse' // eclipse タスク追加(プロジェクト定義)。
apply plugin: 'org.springframework.boot'
apply plugin: 'war' // war タスク追加。
apply plugin: 'com.github.ben-manes.versions' // dependencyUpdates タスク追加。
apply plugin: 'jacoco' // Coverage
war {
baseName = 'template'
version = ''
}
jar {
baseName = 'template'
version = ''
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter() // gradle-versions-plugin で利用
maven { url "http://dl.bintray.com/typesafe/maven-releases" }
}
configurations {
compile.exclude group:'ch.qos.logback' // log4j2 の場合、logback をコンパイル対象から外す
providedRuntime
codacy
}
// thymeleaf 3 以降を利用する場合の定義
ext['thymeleaf.version'] = '3.0.5.RELEASE'
ext['thymeleaf-layout-dialect.version'] = '2.1.2'
task wrapper(type: Wrapper) {
gradleVersion = '3.0'
}
/**
* task:copyToLib
*
* webapp-runner*.jar を build/libs にコピー
*/
task copyToLib(type: Copy) {
into "$buildDir/libs/"
from(configurations.compile) {
include "webapp-runner*"
}
}
/**
* Codacy : https://www.codacy.com
* codacy-coverage-reporter : https://github.com/codacy/codacy-coverage-reporter
*
* coverage : Jacoco
*
* test -> jacocoReport -> uploadCoverageToCodacy
*/
task uploadCoverageToCodacy(type: JavaExec, dependsOn : jacocoTestReport) {
main = "com.codacy.CodacyCoverageReporter"
classpath = configurations.codacy
args = [
"-l",
"Java",
"-r",
"${buildDir}/reports/jacoco/jacocoReport/jacocoReport.xml"
]
}
task (codacyDepsize) << {
def size = 0;
configurations.codacy.collect { it.length() / (1024 * 1024) }.each { size += it }
println "Total dependencies size: ${Math.round(size * 100) / 100} Mb"
configurations
.codacy
.sort { -it.length() }
.each { println "${it.name} : ${Math.round(it.length() / (1024) * 100) / 100} kb" }
}
task (codacyLocs) << {
configurations.codacy.each {
String jarName = it
println jarName
}
}
// war タスク時に copyToLib タスクを先に起動させる。
war.dependsOn copyToLib
/* ---------------------------
依存関係の定義
----------------------------*/
dependencies {
// ---------------------------
// spring-boot 関連, thymeleaf
// ---------------------------
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.thymeleaf.extras:thymeleaf-extras-conditionalcomments')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0')
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '3.0.2.RELEASE'
// ---------------------------
// webjars 関連
// http://www.webjars.org/
// ---------------------------
compile('org.webjars:webjars-locator:0.32')
compile('org.webjars:jquery:2.2.4')
compile('org.webjars:bootstrap:3.3.7-1')
compile('org.webjars:html5shiv:3.7.3')
compile('org.webjars.npm:respond.js:1.4.2')
compile('org.webjars:font-awesome:4.6.3')
compile('org.webjars:Eonasdan-bootstrap-datetimepicker:4.17.37-1')
compile('org.webjars:ace:07.31.2013')
compile('org.webjars.bower:sticky-footer:0.1.4')
compile('org.webjars.npm:bootswatch:3.3.6')
compile('org.webjars:typeaheadjs:0.11.1')
compile('org.webjars:Bootstrap-3-Typeahead:3.1.1')
compile('org.webjars:hoganjs:3.0.2')
compile('org.webjars:bootbox:4.4.0')
compile('org.webjars.npm:bootstrap-dialog:1.34.6')
compile('org.webjars:bootstrap-switch:3.3.2')
// ---------------------------
// etc.. ランタイム、テスト用など
// ---------------------------
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
// https://mvnrepository.com/artifact/com.github.jsimone/webapp-runner
compile group: 'com.github.jsimone', name: 'webapp-runner', version: '8.5.5.0'
compile('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('org.dbunit:dbunit:2.5.3')
codacy group: 'com.codacy', name: 'codacy-coverage-reporter', version: '1.0.10'
// ---------------------------
// SOAP
// ---------------------------
compile("org.springframework.boot:spring-boot-starter-web-services")
compile("wsdl4j:wsdl4j:1.6.3")
// ---------------------------
// REST
// ---------------------------
// https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.8.3'
}
dependencyUpdates.resolutionStrategy = {
// dependencyUpdates の対象から alpha, beta など正式リリース以外はバージョンチェック対象から除外する。
componentSelection { rules ->
rules.all {
ComponentSelection selection ->
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
}
if (rejected) {
selection.reject('Release candidate')
}
}
}
}
// ---------------------------
// charset, encoding
// ---------------------------
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
javadoc {
options.charSet = 'UTF-8'
options.encoding = 'UTF-8'
}
// ---------------------------
// JaCoCo coverage reports
// ---------------------------
jacoco {
applyTo(tasks.withType(JavaExec))
}
test {
jacoco {
enabled = true
destinationFile = file('build/reports/jacoco/jacoco.exec')
}
}
task jacocoReport(type: JacocoReport) {
executionData test
sourceSets project.sourceSets.main
reports {
xml.enabled = true
html.enabled = true
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}