Skip to content

Commit b8313ae

Browse files
committed
Use BuildConfig plugin instead of systemProperty to fix IntelliJ tests
1 parent dfd58cd commit b8313ae

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ buildscript {
1616
plugins {
1717
id 'java'
1818
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
19+
id "com.github.gmazzo.buildconfig" version "2.0.1"
1920
}
2021

2122
apply plugin: 'kotlin'
@@ -40,6 +41,16 @@ idea {
4041
}
4142
}
4243

44+
buildConfig {
45+
className = "BuildConfig"
46+
packageName = "com.tschuchort.compiletesting"
47+
sourceSets {
48+
test {
49+
buildConfigField 'String', 'KOTLIN_VERSION', "\"$kotlin_version\""
50+
}
51+
}
52+
}
53+
4354
dependencies {
4455
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
4556
testImplementation group: 'junit', name: 'junit', version: '4.12'
@@ -75,7 +86,3 @@ compileTestKotlin {
7586
kotlinOptions.jvmTarget = "1.8"
7687
kotlinOptions.freeCompilerArgs += ["-Xskip-runtime-version-check"]
7788
}
78-
79-
test {
80-
systemProperty "KOTLIN_VERSION", "$kotlin_version"
81-
}

src/test/kotlin/com/tschuchort/compiletesting/KotlinCompilationTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class KotlinCompilationTests {
632632
fun `detects the plugin provided for compilation via pluginClasspaths property`() {
633633
val result = defaultCompilerConfig().apply {
634634
sources = listOf(SourceFile.kotlin("kSource.kt", "class KSource"))
635-
pluginClasspaths = listOf(classpathOf("kotlin-scripting-compiler-${System.getProperty("KOTLIN_VERSION")}"))
635+
pluginClasspaths = listOf(classpathOf("kotlin-scripting-compiler-${BuildConfig.KOTLIN_VERSION}"))
636636
}.compile()
637637

638638
assertThat(result.exitCode).isEqualTo(ExitCode.OK)

0 commit comments

Comments
 (0)