Skip to content

Commit

Permalink
follow up of junit-team#2544 to enable a fully resolveable OSGi solution
Browse files Browse the repository at this point in the history
What this means is that merely by consuming the Jupiter client APIs results in requiring a fully fleshed out runtime including launcher as follows
- junit-jupiter-api & junit-jupiter-params depend on junit-platform-commons
- junit-platform-commons Requires a org.junit.platform.engine=*
- junit-jupiter-engine Provides org.junit.platform.engine=junit-jupiter
- junit-vintage-engine Provides org.junit.platform.engine=junit-vintage
- junit-jupiter-engine & junit-vintage-engine Requires org.junit.platform.launcher=junit-platform-launcher
- junit-platform-launcher Provides org.junit.platform.launcher=junit-platform-launcher

The solution is solvable having either junit-jupiter OR junit-vintage on your test classpath

Signed-off-by: Raymond Augé <raymond.auge@liferay.com>
  • Loading branch information
rotty3000 committed Jun 28, 2021
1 parent 6b94826 commit 3cb1b1f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions junit-jupiter-engine/junit-jupiter-engine.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
testImplementation(kotlin("stdlib"))
testImplementation(libs.kotlinx.coroutines)
testImplementation(libs.groovy3)

runtimeOnly(projects.junitPlatformLauncher)
}

tasks {
Expand All @@ -39,6 +41,9 @@ tasks {
org.junit.platform.engine;\
org.junit.platform.engine='junit-jupiter';\
version:Version="${'$'}{version_cleanup;${project.version}}"
Require-Capability:\
org.junit.platform.launcher;\
filter:='(&(org.junit.platform.launcher=junit-platform-launcher)(version>=${'$'}{version_cleanup;${rootProject.property("platformVersion")!!}})(!(version>=${'$'}{versionmask;+;${'$'}{version_cleanup;${rootProject.property("platformVersion")!!}}})))'
""")
}
}
Expand Down
13 changes: 13 additions & 0 deletions junit-platform-commons/junit-platform-commons.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import aQute.bnd.gradle.BundleTaskConvention

plugins {
`java-library-conventions`
`java-multi-release-sources`
Expand All @@ -11,11 +13,22 @@ dependencies {
api(platform(projects.junitBom))

compileOnlyApi(libs.apiguardian)

runtimeOnly(projects.junitJupiterEngine)
}

tasks.jar {
val release9ClassesDir = sourceSets.mainRelease9.get().output.classesDirs.singleFile
inputs.dir(release9ClassesDir).withPathSensitivity(PathSensitivity.RELATIVE)

withConvention(BundleTaskConvention::class) {
bnd("""
Require-Capability:\
org.junit.platform.engine;\
filter:='(&(org.junit.platform.engine=*)(version>=${'$'}{version_cleanup;${rootProject.property("version")!!}})(!(version>=${'$'}{versionmask;+;${'$'}{version_cleanup;${rootProject.property("version")!!}}})))'
""")
}

doLast {
exec {
executable = project.the<JavaToolchainService>().launcherFor(java.toolchain).get()
Expand Down
15 changes: 15 additions & 0 deletions junit-platform-launcher/junit-platform-launcher.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import aQute.bnd.gradle.BundleTaskConvention

plugins {
`java-library-conventions`
`java-test-fixtures`
Expand All @@ -11,3 +13,16 @@ dependencies {

compileOnlyApi(libs.apiguardian)
}

tasks {
jar {
withConvention(BundleTaskConvention::class) {
bnd("""
Provide-Capability:\
org.junit.platform.launcher;\
org.junit.platform.launcher='junit-platform-launcher';\
version:Version="${'$'}{version_cleanup;${project.version}}"
""")
}
}
}
5 changes: 5 additions & 0 deletions junit-vintage-engine/junit-vintage-engine.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
testImplementation(projects.junitPlatformLauncher)
testImplementation(projects.junitPlatformRunner)
testImplementation(projects.junitPlatformTestkit)

runtimeOnly(projects.junitPlatformLauncher)
}

tasks {
Expand Down Expand Up @@ -53,6 +55,9 @@ tasks {
org.junit.platform.engine;\
org.junit.platform.engine='junit-vintage';\
version:Version="${'$'}{version_cleanup;${project.version}}"
Require-Capability:\
org.junit.platform.launcher;\
filter:='(&(org.junit.platform.launcher=junit-platform-launcher)(version>=${'$'}{version_cleanup;${rootProject.property("platformVersion")!!}})(!(version>=${'$'}{versionmask;+;${'$'}{version_cleanup;${rootProject.property("platformVersion")!!}}})))'
""")
}
}
Expand Down

0 comments on commit 3cb1b1f

Please sign in to comment.