-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
294 lines (247 loc) · 9.82 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
import de.itemis.mps.gradle.*
import de.itemis.mps.gradle.downloadJBR.*
import de.itemis.mps.gradle.tasks.*
buildscript {
repositories {
maven { url 'https://artifacts.itemis.cloud/repository/maven-mps/' }
}
dependencies {
classpath 'de.itemis.mps.gradle:git-based-versioning:1.1.0'
}
}
plugins {
id 'de.itemis.mps.gradle.common' version '1.28.0.+'
id 'download-jbr' version '1.28.0.+'
id 'base'
id 'maven-publish'
id 'co.riiid.gradle' version '0.4.2'
id 'de.itemis.mps.gradle.launcher' version '2.2.0.+'
}
ext.jbrVers = '17.0.6-b653.34'
downloadJbr {
jbrVersion = jbrVers
}
// detect if we are in a CI build
if (System.env.CI != null && System.env.CI.toBoolean()) {
// is this github
ext.ciBuild = true
} else {
// on teamcity we are in a CI build
ext.ciBuild = project.hasProperty("teamcity")
}
// Detect jdk location, required to start ant with tools.jar on classpath otherwise javac and tests will fail
String jdk_home
if (ext.has('java11_home')) {
jdk_home = ext.get('java11_home')
} else if (System.getenv('JB_JAVA11_HOME') != null) {
jdk_home = System.getenv('JB_JAVA11_HOME')
} else {
def expected = JavaVersion.VERSION_11
if (JavaVersion.current() != expected) {
throw new GradleException("This build script requires Java 11 but you are currently using ${JavaVersion.current()}.\nWhat you can do:\n"
+ " * Use project property java11_home to point to the Java 11 JDK.\n"
+ " * Use environment variable JB_JAVA11_HOME to point to the Java 11 JDK\n"
+ " * Run Gradle using Java 11")
}
jdk_home = System.getProperty('java.home')
}
// Check JDK location
if (!new File(jdk_home, "lib").exists()) {
throw new GradleException("Unable to locate JDK home folder. Detected folder is: $jdk_home")
}
logger.info 'Using JDK at {}', jdk_home
ext.jdk_home = jdk_home
ext.dependencyRepositories = [
'https://maven.pkg.github.com/mbeddr/*',
'https://artifacts.itemis.cloud/repository/maven-mps/'
]
// Dependency versions
ext.mpsVersion = '2022.3.2'
// Project versions
ext.major = '2022'
ext.minor = '3'
if (ciBuild) {
String branch = GitBasedVersioning.gitBranch
def buildNumber = System.env.GITHUB_RUN_NUMBER != null ? System.env.GITHUB_RUN_NUMBER.toInteger() : System.env.BUILD_NUMBER.toInteger()
if (branch.startsWith("maintenance") || branch.startsWith("mps")) {
version = "$major.$minor.$buildNumber.${GitBasedVersioning.gitShortCommitHash}"
} else {
version = GitBasedVersioning.getVersionWithCount(major, minor, buildNumber)
}
println "##teamcity[buildNumber '${version}']"
} else {
println "Local build detected, version will be SNAPSHOT"
version = "$major.$minor-SNAPSHOT"
}
configurations {
mps
languageLibs
// includes also junit tasks support
antLib
}
dependencies {
mps "com.jetbrains:mps:$mpsVersion"
antLib "org.apache.ant:ant-junit:1.10.6"
}
repositories {
for (repoUrl in project.dependencyRepositories) {
maven {
url repoUrl
credentials {
username = project.findProperty("github_username") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("github_token") ?: System.getenv("GITHUB_TOKEN")
}
}
}
mavenCentral()
}
ext.skipResolveMps = project.hasProperty('mpsHomeDir')
ext.mpsHomeDir = rootProject.file(project.findProperty('mpsHomeDir') ?: "$buildDir/mps")
if (project.skipResolveMps) {
task resolveMps {
doLast {
logger.info "MPS resolution skipped"
logger.info "MPS home: " + mpsHomeDir.getAbsolutePath()
}
}
} else {
task resolveMps(type: Sync) {
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into mpsHomeDir
}
}
// tools needed for compiler support in ant calls
ext.buildScriptClasspath = project.configurations.antLib.fileCollection { true } +
project.files("$project.jdk_home/lib/tools.jar")
def artifactsDir = file("$buildDir/artifacts")
def dependenciesDir = file("$buildDir/dependencies")
// ___________________ utilities ___________________
def defaultScriptArgs = [
'mps.home' : mpsHomeDir,
'mps_home' : mpsHomeDir,
'build.jna.library.path' : new File(mpsHomeDir, "lib/jna/${System.getProperty('os.arch')}"),
'com.mbeddr.logicalview.checks.home' : rootDir,
'build.dir' : buildDir,
'version' : version,
'build.date' : new Date(),
]
// enables https://github.com/mbeddr/mps-gradle-plugin#providing-global-defaults
task configureJava {
dependsOn "downloadJbr"
doLast {
project.ext["itemis.mps.gradle.ant.defaultScriptArgs"] = defaultScriptArgs.collect { "-D$it.key=$it.value".toString() }
project.ext["itemis.mps.gradle.ant.defaultScriptClasspath"] = buildScriptClasspath
project.ext["itemis.mps.gradle.ant.defaultJavaExecutable"] = tasks.getByName("downloadJbr").javaExecutable
println project.findProperty("itemis.mps.gradle.ant.defaultJavaExecutable")
}
}
// All MPS tasks depend on configureJava and resolveMps
tasks.withType(RunAntScript).configureEach {
dependsOn(configureJava, resolveMps)
}
File scriptFile(String name) {
file("$buildDir/scripts/$name")
}
def build_allScripts = tasks.register('build_allScripts', BuildLanguages) {
dependsOn 'downloadJbr', resolveMps
script "$rootDir/scripts/build.xml"
}
// All other MPS tasks depend on build_allScripts
tasks.withType(RunAntScript).configureEach {
if (it.name != build_allScripts.name) {
it.dependsOn(build_allScripts)
}
}
def build_languages = tasks.register('build_languages', BuildLanguages) {
mustRunAfter('clean')
dependsOn build_allScripts
script scriptFile('languages/build.xml')
}
task package_project(type: Zip) {
dependsOn build_allScripts
archiveBaseName = 'com.mbeddr.logicalview.checks'
from artifactsDir
include 'com.mbeddr.logicalview.checks/**'
}
assemble.dependsOn(tasks.withType(BuildLanguages))
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/mbeddr/mps-logical-view-checks")
credentials {
username = project.findProperty("github_username") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("github_token") ?: System.getenv("GITHUB_TOKEN")
}
}
if (project.hasProperty("artifacts.itemis.cloud.user") && project.hasProperty("artifacts.itemis.cloud.pw")) {
maven {
name = "ItemisNexus"
url = uri("https://artifacts.itemis.cloud/repository/maven-mps-releases")
credentials {
username = project.findProperty("artifacts.itemis.cloud.user")
password = project.findProperty("artifacts.itemis.cloud.pw")
}
}
}
}
publications {
MPSLogicalViewChecks(MavenPublication) {
groupId 'com.mbeddr'
artifactId 'logicalview.checks'
artifact package_project
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.languageLibs.resolvedConfiguration.firstLevelModuleDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.moduleGroup)
dependencyNode.appendNode('artifactId', it.moduleName)
dependencyNode.appendNode('version', it.moduleVersion)
dependencyNode.appendNode('type', it.moduleArtifacts[0].type)
}
configurations.mps.resolvedConfiguration.firstLevelModuleDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.moduleGroup)
dependencyNode.appendNode('artifactId', it.moduleName)
dependencyNode.appendNode('version', it.moduleVersion)
dependencyNode.appendNode('type', it.moduleArtifacts[0].type)
dependencyNode.appendNode('scope', 'provided')
}
}
}
}
}
task cleanMps(type: Delete) {
delete fileTree(dir: projectDir, include: ["**/classes_gen/**", "**/source_gen/**", "**/source_gen.caches/**", "tmp/**"])
}
clean.dependsOn cleanMps
defaultTasks 'build'
task rebuild(dependsOn:[clean, build_languages])
ext.mpsPluginRoots = ['mps-build', 'mps-console', 'mps-trove', 'mps-modelchecker']
.collect { new File(mpsHomeDir, "plugins/$it") }
ext.jbrJavaLauncher = tasks.named('downloadJbr', DownloadJbrForPlatform).flatMap { it.javaLauncher }
tasks.register('migrate', MpsMigrate) {
dependsOn(resolveMps, 'downloadJbr', 'build_languages')
javaLauncher = jbrJavaLauncher
mpsHome = mpsHomeDir
folderMacros.put('com.mbeddr.logicalview.checks.home', layout.projectDirectory)
projectDirectories.from('code')
pluginRoots.from(mpsPluginRoots)
haltOnPrecheckFailure = true
haltOnDependencyError = true
}
tasks.register('remigrate', Remigrate) {
dependsOn(resolveMps, 'downloadJbr')
mustRunAfter('migrate')
// Technically we don't need to _depend_ on build_all_languages because we can opt to rerun only migrations that
// come from MPS.
mustRunAfter('build_languages')
javaLauncher = jbrJavaLauncher
mpsHome = mpsHomeDir
folderMacros.put('com.mbeddr.logicalview.checks.home', layout.projectDirectory)
projectDirectories.from('code')
pluginRoots.from(mpsPluginRoots)
}