-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.gradle
202 lines (181 loc) · 6.59 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
/* file: build.gradle
*
* Gradle related files:
*
* - gradle.properties (to start the gradle process itself)
* - settings.gradle (loaded before build.gradle)
*
* Sub projects:
*
* - armadillo/build.gradle
* - r/build.gradle
* - ui/build.gradle
*/
plugins {
id 'org.springframework.boot' version '3.2.3'
id "io.spring.dependency-management" version "1.1.4"
id "java"
id "org.sonarqube" version "4.4.1.3373"
id 'maven-publish'
id 'application'
id "jacoco"
id 'com.palantir.docker' version '0.36.0'
id 'se.patrikerdes.use-latest-versions' version '0.2.18'
id 'com.github.ben-manes.versions' version '0.51.0'
}
targetCompatibility = '17'
sourceCompatibility = '17'
println "Project previous version (nyx): " + rootProject.nyxState.releaseScope.previousVersion
allprojects {
group = 'org.molgenis'
if(rootProject.nyxState.releaseScope.previousVersion == rootProject.version ||
//temporarily also compare to 'v' because we are remove this prefix
rootProject.nyxState.releaseScope.previousVersion == "v" + rootProject.version ) {
version = rootProject.nyxState.releaseScope.previousVersion + "-SNAPSHOT"
}
else {
version = rootProject.version.replace("SNAPSHOT.1","SNAPSHOT")
}
version = version.replace("v","")
}
if(getGitNameRef().contains("tags/") && !getGitNameRef().contains("~")) {
def x = getGitNameRef().replace("tags/", "")
println "HEAD is on tag so removing SNAPSHOT: " + x
version = version.replace("-SNAPSHOT", "")
}
else {
//version = version + "-" + gitHash
}
println "Corrected version checking for optional snapshot: " + rootProject.version
nyxPublish.dependsOn assemble
println "Project version : " + version
println "Git version : " + gitHash
println "Git name-ref : " + getGitNameRef()
repositories {
mavenLocal()
maven {
url = 'https://repo.maven.apache.org/maven2'
}
maven {
url = 'https://obiba.jfrog.io/artifactory/libs-release-local/'
}
}
//helper function to get the githash
String getGitHash() {
// git hash
def command = Runtime.getRuntime().exec("git rev-parse --short HEAD")
def result = command.waitFor()
if (result != 0) {
throw new IOException("Command 'getGitHash()' exited with " + result)
}
String gitCommitHash = command.inputStream.text.trim()
return gitCommitHash
}
String getGitNameRef() {
def command = Runtime.getRuntime().exec("git name-rev --name-only HEAD")
def result = command.waitFor()
if (result != 0) {
throw new IOException("Command 'getGitNameRef()' exited with " + result)
}
String gitCommitHash = command.inputStream.text.trim()
return gitCommitHash
}
// configure artifact
mainClassName = 'org.molgenis.armadillo.ArmadilloServiceApplication'
dependencies {
implementation project(':armadillo')
}
jar {
//we gonna use spring jar, below
enabled = false
}
springBoot {
buildInfo()
}
bootJar {
mainClass = mainClassName
manifest {
attributes(
'Specification-Version': project.version.toString(),
'Implementation-Version': getGitHash(),
'Created-By': "Gradle ${gradle.gradleVersion}",
'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS': "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
}
//define run
application {
mainClass.set(rootProject.mainClassName)
}
//define release
project.ext.ghToken = project.hasProperty('ghToken') ? project.getProperty('ghToken') : System.getenv('GITHUB_TOKEN') ?: null
//define docker image
def imageName = 'docker.io/molgenis/molgenis-armadillo'
def tagName = project.version.toString()
if (version.toString().endsWith('-SNAPSHOT')) {
ext.hash = 'git rev-parse --short HEAD'.execute().text.trim()
imageName = "docker.io/molgenis/molgenis-armadillo-snapshot"
tagName = "${project.version.toString()}-${ext.hash}"
}
task ci(type: WriteProperties) {
outputFile file('build/ci.properties')
property 'TAG_NAME', tagName
}
docker {
name imageName
tags 'latest', tagName
dockerfile file('Dockerfile')
files bootJar.archiveFile
buildArgs(['JAR_FILE': "${bootJar.archiveFile.get().asFile.name}"])
}
dockerPrepare.dependsOn bootJar
//merge test reports
task jacocoMergedReport(type: JacocoReport) {
dependsOn project.getTasksByName(":armadillo:test", true)
dependsOn project.getTasksByName(":r:test", true)
dependsOn project.getTasksByName("jacocoTestReport", true)
dependsOn project.getTasksByName("jacocoTestReport", true)
dependsOn project.getTasksByName("bootStartScripts", true)
dependsOn project.getTasksByName("startScripts", true)
additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories.setFrom files(subprojects.sourceSets.main.output)
executionData.setFrom project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
reports {
xml.required = true
csv.required = false
html.required = false
}
}
//push to sonarqube
sonarqube {
properties {
// Uncomment when upgrading to sonar 5.x
// property 'sonar.gradle.skipCompile', 'true'
property 'sonar.projectName', 'armadillo-service'
property 'sonar.projectKey', 'org.molgenis:armadillo-service'
property 'sonar.coverage.jacoco.xmlReportPaths', "${projectDir}/build/reports/jacoco/jacocoMergedReport/jacocoMergedReport.xml"
}
}
//install pre-commit hook
task installLocalGitHook(type: Copy) {
from new File(rootProject.rootDir, 'pre-commit')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0775
}
build.dependsOn installLocalGitHook
task myNyxDiagnostics() {
// https://mooltiverse.github.io/nyx/guide/user/introduction/usage/#accessing-the-nyx-state-extra-project-property-from-build-scripts
dependsOn nyxInfer
doLast {
println "Nyx dump > =============="
println "Current : " + rootProject.nyxState.releaseScope.previousVersion
println "Bump level : " + project.nyxState.bump
println "Scheme : " + project.nyxState.scheme.toString()
println "Timestamp : " + Long.valueOf(project.nyxState.timestamp).toString()
println "Version : " + project.nyxState.version
println "# of commits: " + project.nyxState.releaseScope.significantCommits.size()
println "Nyx dump < =============="
}
}