File tree 3 files changed +36
-4
lines changed
src/main/kotlin/com/tschuchort/compiletesting
3 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 1
1
// file:noinspection GroovyAssignabilityCheck
2
+ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
2
3
3
4
plugins {
4
5
id " com.github.gmazzo.buildconfig" version " 3.1.0"
@@ -16,6 +17,18 @@ buildConfig {
16
17
}
17
18
}
18
19
20
+ configurations. all {
21
+ resolutionStrategy. dependencySubstitution {
22
+ substitute(module(" org.jetbrains.kotlin:kotlin-dom-api-compat" ))
23
+ .using variant(module(" org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version " )) {
24
+ attributes {
25
+ attribute(KotlinPlatformType . attribute, KotlinPlatformType . js)
26
+ attribute(Usage . USAGE_ATTRIBUTE , project. objects. named(Usage , " kotlin-runtime" ))
27
+ }
28
+ }
29
+ }
30
+ }
31
+
19
32
dependencies {
20
33
compileOnly ' com.google.auto.service:auto-service:1.1.1'
21
34
kapt " com.google.auto.service:auto-service:1.1.1"
@@ -31,7 +44,9 @@ dependencies {
31
44
// running compiler plugins passed via the pluginClasspath CLI option works
32
45
testRuntimeOnly " org.jetbrains.kotlin:kotlin-scripting-compiler:$embedded_kotlin_version "
33
46
34
- // testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$embedded_kotlin_version"
47
+ // Include Kotlin/JS standard library in test classpath for auto loading
48
+ testRuntimeOnly " org.jetbrains.kotlin:kotlin-stdlib-js"
49
+ testRuntimeOnly " org.jetbrains.kotlin:kotlin-dom-api-compat"
35
50
36
51
// The Kotlin compiler should be near the end of the list because its .jar file includes
37
52
// 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 @@ -52,6 +52,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
52
52
HostEnvironment .kotlinStdLibJsJar
53
53
}
54
54
55
+ /* *
56
+ * Path to the kotlin-dom-api-compat.klib
57
+ * If none is given, it will be searched for in the host
58
+ * process' classpaths
59
+ */
60
+ var kotlinStdLibDomApi: File ? by default {
61
+ HostEnvironment .kotlinDomApiCompatKlib
62
+ }
63
+
55
64
/* *
56
65
* Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only
57
66
*/
@@ -90,7 +99,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
90
99
args.moduleName = moduleName // -ir-output-name
91
100
args.outputFile = File (outputDir, outputFileName).absolutePath
92
101
args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File .pathSeparator)
93
- args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = " : " )
102
+ args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi ).joinToString(separator = File .pathSeparator )
94
103
95
104
args.irProduceKlibDir = irProduceKlibDir
96
105
args.irProduceKlibFile = irProduceKlibFile
You can’t perform that action at this time.
0 commit comments