Skip to content

Commit aaf891e

Browse files
committed
workaround to junit launcher issue in intellij 2022.2 plus gradle 7.5.1
Signed-off-by: shalom <[email protected]>
1 parent 9800ffc commit aaf891e

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

analytics-provider/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ dependencies {
1313

1414

1515
testing {
16+
//basic shared configuration is in buildSrc/src/main/kotlin/digma-base.gradle.kts
17+
1618
suites {
1719
val test by getting(JvmTestSuite::class) {
18-
useJUnitJupiter(libs.versions.junit.get())
1920

2021
dependencies {
2122
implementation(project)

buildSrc/src/main/kotlin/common-kotlin.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ kotlin {
2929
}
3030

3131

32+
dependencies{
33+
//add the kotlin test library to all projects that apply this common-kotlin plugin.
34+
//so all project are ready to use kotlin test
35+
testImplementation(kotlin("test"))
36+
}
37+
3238
tasks{
3339
properties("javaVersion", project).let {
3440
withType<KotlinCompile> {

buildSrc/src/main/kotlin/digma-base.gradle.kts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
77

88
plugins{
99
`java`
10+
`jvm-test-suite`
1011
id("com.dorongold.task-tree")
1112
id("com.glovoapp.semantic-versioning")
1213
}
@@ -60,6 +61,43 @@ project.afterEvaluate{
6061
}
6162

6263

64+
65+
testing {
66+
//https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html
67+
68+
//this is the basic configuration of the test task for all projects.
69+
//it can be extended in projects to add dependencies and other configuration.
70+
//see for example analytics-provider project.
71+
//jvmTestSuite eventually adds a test task to every project so the test task can also be configured
72+
//independently like in legacy gradle versions. for example just adding testImplementation dependencies.
73+
//but extending jvmTestSuite like in analytics-provider is more consice and safe with regards to depenency hell.
74+
//so all projects are already configured to use junit jupiter.
75+
76+
suites {
77+
val test by getting(JvmTestSuite::class) {
78+
//this is the only place junit version should be mentioned in the project.
79+
//it applies to all projects. can't use versions catalog in scripts plugins so using
80+
//hard coded version.
81+
useJUnitJupiter("5.8.2")
82+
83+
dependencies {
84+
implementation(project)
85+
86+
//this is a workaround to an issue with junit launcher in intellij platform 2022.2 plus gradle 7.5.1.
87+
//it is discussed in a slack thread and will probably be fixed in the next intellij platform patch.
88+
//todo: when upgrading the platform version check if its fixed just by removing it and building the project with no errors.
89+
//https://jetbrains-platform.slack.com/archives/CPL5291JP/p1660085792256189
90+
runtimeOnly("org.junit.platform:junit-platform-launcher")
91+
runtimeOnly("org.junit.jupiter:junit-jupiter-engine")
92+
}
93+
}
94+
}
95+
}
96+
97+
98+
99+
100+
63101
tasks{
64102

65103
withType<JavaCompile> {

ide-common/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ dependencies {
1919

2020
implementation(project(":model"))
2121
implementation(project(":analytics-provider"))
22-
23-
testImplementation(kotlin("test"))
2422
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.digma.intellij.plugin.test;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
7+
class ExampleJavaTest {
8+
9+
//this test is just for checking that the workaround in buildSrc/src/main/kotlin/digma-base.gradle.kts
10+
//testing extension really works. see the dependency:
11+
//runtimeOnly("org.junit.platform:junit-platform-launcher")
12+
//runtimeOnly("org.junit.jupiter:junit-jupiter-engine")
13+
//when it's fixed in intellij we can delete this test
14+
15+
@Test
16+
void testMe() {
17+
Assertions.assertTrue(1 > 0);
18+
}
19+
20+
}

model/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ dependencies {
1515
//add kotlin stdlib version compatible with the intellij platform we're building for.
1616
//compileOnly because we don't need to package it in the plugin zip.
1717
compileOnly(libs.kotlin.stdlib.jdk8)
18-
19-
testImplementation(kotlin("test"))
2018
}

settings.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencyResolutionManagement {
3333
version("intellij-platform", "2022.2")
3434
//rdgen version is not always the same as platform version
3535
version("rider-rdgen", "2022.2.5")
36-
version("junit", "5.8.2")
3736
//kotlin stdlib is not packaged with the plugin because intellij platform already contains it.
3837
//it's necessary for compilation in some cases for example rider protocol module.
3938
//it must target the lowest bundled stdlib version of the platform we support

0 commit comments

Comments
 (0)