Skip to content

Commit 75c0b7a

Browse files
vRallevtschuchortdev
authored andcommitted
Add a convenience method to add the result of a compilation to another compilation.
1 parent e383cc8 commit 75c0b7a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,3 +681,15 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
681681
const val OPTION_KAPT_KOTLIN_GENERATED = "kapt.kotlin.generated"
682682
}
683683
}
684+
685+
/**
686+
* Adds the output directory of [previousResult] to the classpath of this compilation. This is a convenience for
687+
* ```
688+
* this.classpaths += previousResult.outputDirectory
689+
* ```
690+
*/
691+
fun KotlinCompilation.addPreviousResultToClasspath(
692+
previousResult: KotlinCompilation.Result
693+
): KotlinCompilation = apply {
694+
classpaths += previousResult.outputDirectory
695+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ class KotlinCompilationTests {
894894
.apply {
895895
sources = listOf(kSource2)
896896
inheritClassPath = true
897-
classpaths += result.outputDirectory
898897
}
898+
.addPreviousResultToClasspath(result)
899899
.compile()
900900
.apply {
901901
assertThat(exitCode).isEqualTo(ExitCode.OK)

0 commit comments

Comments
 (0)