-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.gradle
150 lines (110 loc) · 3.3 KB
/
common.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
// overrides default "build"
buildDir file("target")
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
ext.getNightly = { flixHome ->
def jars = fileTree(flixHome).filter { it.name.matches("flix-.*\\.jar") }.files
if (jars.size() > 0) {
def jarName = jars.last().name
logger.warn("Nightly build '$jarName' was selected")
return jarName
}
else {
logger.warn("> WARNING: No nightly build of Flix was found; use release version instead.")
return "flix.jar"
}
}
ext.convertPath = { path ->
if (path.startsWith("/cygdrive/")) {
return path[10] + ":" + path.substring(11)
}
else {
return path
}
}
project.ext {
configurations {
bootClasspath
}
repositories {
mavenCentral()
}
dependencies {
// see flix.jar:library.properties
bootClasspath "org.scala-lang:scala-library:2.13.14"
}
flixHome = System.getenv("FLIX_HOME")
logger.info("flixHome = $flixHome")
jarName = System.getProperty("nightly") != null
? getNightly(flixHome)
: "flix.jar"
flixJar = file(convertPath(flixHome) + "/" + jarName)
mainSourceTree = fileTree(dir: "src/main", include: "**/*.flix")
//testSourceTree = fileTree(dir: "src/test", include: "**/*.flix")
buildAppDir = file("${buildDir}/${appName}")
}
clean.doLast {
buildDir.deleteDir()
}
tasks.withType(JavaCompile) {
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
options.deprecation true
options.encoding "UTF8"
}
task initFlix(type: JavaExec) {
jvmArgs "-Dfile.encoding=UTF-8"
mainClass = "-jar"
args = [ flixJar, "init" ]
workingDir buildAppDir
}
initFlix.doFirst {
buildAppDir.mkdirs()
}
initFlix.onlyIf {
! buildAppDir.exists()
}
task deleteFiles(type: Delete) {
dependsOn initFlix
delete fileTree("${buildAppDir}/src") { include "**/*.flix" }
delete fileTree("${buildAppDir}/test") { include "**/*.flix" }
}
task copyFlix(type: Copy) {
dependsOn initFlix, deleteFiles
from("src/main") { include "**/*.flix" }
into "${buildAppDir}/src"
}
task compileFlix(type: JavaExec) {
dependsOn copyFlix, compileJava
description "Compile Flix source files"
jvmArgs "-Dfile.encoding=UTF-8"
mainClass = "-jar"
args = [ flixJar, "build" ]
workingDir buildAppDir
}
compileFlix.onlyIf {
! mainSourceTree.isEmpty()
}
task jarFlix(type: JavaExec) {
dependsOn compileFlix
description "Create Flix program \"${appName}/${appName}.jar\""
jvmArgs "-Dfile.encoding=UTF-8"
mainClass = "-jar"
args = [ flixJar, "build-jar" ]
workingDir buildAppDir
}
build {
dependsOn jarFlix
}
task run(type: JavaExec) {
dependsOn build
description "Execute Flix program \"${appName}/${appName}.jar\""
jvmArgs "-Dfile.encoding=UTF-8"
def bootClasspath = fileTree(dir: "${buildAppDir}/lib", include: "**/*.jar").join(File.pathSeparator)
// Starting with version 0.35.0 Flix generates the jar file into directory 'artifact'.
def appJar = "${buildAppDir}${File.separator}artifact${File.separator}${appName}.jar"
mainClass = "-Xbootclasspath/a:${bootClasspath}"
args = [ "-jar", "${appJar}" ]
workingDir buildAppDir
}