This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.gradle.kts
161 lines (132 loc) · 4.44 KB
/
build.gradle.kts
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
/*
* GNU General Public License version 2
*
* Copyright (C) 2019-2020 JetBrains s.r.o.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import java.util.*
plugins {
kotlin("jvm")
application
}
val localProperties = Properties().apply {
try {
load(File(rootDir, "local.properties").inputStream())
}
catch (t: Throwable) {
println("Can't read local.properties: $t, assuming empty")
}
}
val projectorServerSource = (localProperties["projectorServerSource"] as String?)?.substringBefore('-')
val projectorServerVersion = (localProperties["projectorServerSource"] as String?)?.substringAfter('-')
repositories {
mavenCentral()
if (projectorServerSource == "space") {
maven("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies")
}
else {
maven("https://jitpack.io")
}
}
val originalMain = "org.jetbrains.projector.demo.OriginalMain"
val headlessSupportingMain = "org.jetbrains.projector.demo.HeadlessSupportingMain"
application {
mainClass.set(originalMain)
}
group = "org.jetbrains.projector"
version = "1.0-SNAPSHOT"
val jarOriginalConf: Configuration by configurations.creating
val kotlinVersion: String by project
val targetJvm: String by project
tasks.withType<KotlinJvmCompile> {
kotlinOptions {
jvmTarget = targetJvm
}
}
configurations.all {
// disable caching of -SNAPSHOT dependencies
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
when (projectorServerSource) {
"space" -> {
implementation("org.jetbrains.projector:projector-server:$projectorServerVersion")
}
"jitpack" -> {
implementation("com.github.JetBrains.projector-server:projector-server:$projectorServerVersion")
}
"local", null -> {
implementation("com.github.JetBrains.projector-server:projector-server:-SNAPSHOT")
}
else -> {
throw IllegalStateException("Unknown projectorServerSource = '$projectorServerSource'")
}
}
jarOriginalConf("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
jarOriginalConf("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
}
fun Project.inline(conf: Configuration): Iterable<Any> {
return conf.map { it: File -> if (it.isDirectory) it else zipTree(it) }
}
val jarOriginal by tasks.creating(Jar::class) {
manifest {
attributes(
"Main-Class" to originalMain,
)
}
exclude("META-INF/versions/9/module-info.class")
archiveBaseName.set("${project.name}-original")
from(inline(jarOriginalConf))
with(tasks.jar.get())
}
val jarHeadlessSupport by tasks.creating(Jar::class) {
manifest {
attributes(
"Main-Class" to headlessSupportingMain,
)
}
exclude("META-INF/versions/9/module-info.class")
archiveBaseName.set("${project.name}-headless-support")
from(inline(configurations.runtimeClasspath.get()))
with(tasks.jar.get())
}
tasks.build {
dependsOn(jarOriginal, jarHeadlessSupport)
}
fun createRunner(mainClassName: String, vararg jvmArgs: String) = tasks.creating(JavaExec::class) {
group = "application"
mainClass.set(mainClassName)
classpath(sourceSets["main"].runtimeClasspath)
jvmArgs(*jvmArgs)
}
val runUiOriginalMain by createRunner(
mainClassName = originalMain,
)
val runUiHeadlessSupportingMain by createRunner(
mainClassName = headlessSupportingMain,
)
val runHeadlessHeadlessSupportingMain by createRunner(
mainClassName = headlessSupportingMain,
"-Dorg.jetbrains.projector.server.enable=true",
"-Djdk.attach.allowAttachSelf=true",
)
val runHeadlessProjectorLauncher by createRunner(
mainClassName = "org.jetbrains.projector.server.ProjectorLauncher",
"-Dorg.jetbrains.projector.server.classToLaunch=$originalMain",
"-Djdk.attach.allowAttachSelf=true",
)