File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
src/main/kotlin/com/tschuchort/compiletesting Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change
1
+ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
1
2
2
3
plugins {
3
4
id " com.github.gmazzo.buildconfig" version " 3.1.0"
@@ -15,6 +16,18 @@ buildConfig {
15
16
}
16
17
}
17
18
19
+ configurations. all {
20
+ resolutionStrategy. dependencySubstitution {
21
+ substitute(module(" org.jetbrains.kotlin:kotlin-dom-api-compat" ))
22
+ .using variant(module(" org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version " )) {
23
+ attributes {
24
+ attribute(KotlinPlatformType . attribute, KotlinPlatformType . js)
25
+ attribute(Usage . USAGE_ATTRIBUTE , project. objects. named(Usage , " kotlin-runtime" ))
26
+ }
27
+ }
28
+ }
29
+ }
30
+
18
31
dependencies {
19
32
compileOnly " com.google.auto.service:auto-service:1.0.1"
20
33
kapt " com.google.auto.service:auto-service:1.0.1"
@@ -32,6 +45,7 @@ dependencies {
32
45
33
46
// Include Kotlin/JS standard library in test classpath for auto loading
34
47
testRuntimeOnly " org.jetbrains.kotlin:kotlin-stdlib-js"
48
+ testRuntimeOnly " org.jetbrains.kotlin:kotlin-dom-api-compat"
35
49
36
50
// The Kotlin compiler should be near the end of the list because its .jar file includes
37
51
// an obsolete version of Guava
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ internal object HostEnvironment {
27
27
findInClasspath(kotlinDependencyRegex(" kotlin-stdlib-js" ))
28
28
}
29
29
30
+ val kotlinDomApiCompatKlib: File ? by lazy {
31
+ findInClasspath(kotlinDependencyRegex(" kotlin-dom-api-compat" ))
32
+ }
33
+
30
34
val kotlinReflectJar: File ? by lazy {
31
35
findInClasspath(kotlinDependencyRegex(" kotlin-reflect" ))
32
36
}
@@ -40,7 +44,7 @@ internal object HostEnvironment {
40
44
}
41
45
42
46
private fun kotlinDependencyRegex (prefix : String ): Regex {
43
- return Regex (" $prefix (-[0-9]+\\ .[0-9]+(\\ .[0-9]+)?)([-0-9a-zA-Z]+)?\\ .jar" )
47
+ return Regex (" $prefix (-[0-9]+\\ .[0-9]+(\\ .[0-9]+)?)([-0-9a-zA-Z]+)?( \\ .jar| \\ .klib) " )
44
48
}
45
49
46
50
/* * Tries to find a file matching the given [regex] in the host process' classpath */
@@ -60,7 +64,11 @@ internal object HostEnvironment {
60
64
61
65
val classpaths = classGraph.classpathFiles
62
66
val modules = classGraph.modules.mapNotNull { it.locationFile }
67
+ val klibs = System .getProperty(" java.class.path" )
68
+ .split(File .pathSeparator)
69
+ .filter { it.endsWith(" .klib" ) }
70
+ .map(::File )
63
71
64
- return (classpaths + modules).distinctBy(File ::getAbsolutePath)
72
+ return (classpaths + modules + klibs ).distinctBy(File ::getAbsolutePath)
65
73
}
66
74
}
Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
47
47
HostEnvironment .kotlinStdLibJsJar
48
48
}
49
49
50
+ /* *
51
+ * Path to the kotlin-dom-api-compat.klib
52
+ * If none is given, it will be searched for in the host
53
+ * process' classpaths
54
+ */
55
+ var kotlinStdLibDomApi: File ? by default {
56
+ HostEnvironment .kotlinDomApiCompatKlib
57
+ }
58
+
50
59
/* *
51
60
* Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only
52
61
*/
@@ -84,7 +93,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
84
93
args.outputDir = outputDir.absolutePath // -ir-output-dir
85
94
args.moduleName = Paths .get(outputFileName).nameWithoutExtension // -ir-output-name
86
95
args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File .pathSeparator)
87
- args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = " : " )
96
+ args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi ).joinToString(separator = File .pathSeparator )
88
97
89
98
args.irProduceKlibDir = irProduceKlibDir
90
99
args.irProduceKlibFile = irProduceKlibFile
You can’t perform that action at this time.
0 commit comments