-
Notifications
You must be signed in to change notification settings - Fork 1k
/
testng-test-osgi-build.gradle.kts
87 lines (77 loc) · 3.74 KB
/
testng-test-osgi-build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
plugins {
id("testng.java-library")
}
val testngRepository by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
description =
"Consumes local maven repository directory that contains the artifacts produced by :testng"
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named("maven-repository"))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
}
}
dependencies {
testngRepository(projects.testng)
testImplementation(projects.testng)
testImplementation("javax:javaee-api:8.0.1") {
// The dependency was not obvious, logged https://github.com/cbeust/testng/issues/2578
because("PaxExam uses javax.transaction.NotSupportedException and other classes")
}
testImplementation("org.ops4j.pax.exam:pax-exam-container-native:4.13.1")
// pax-exam is not yet compatible with junit5
// see https://github.com/ops4j/org.ops4j.pax.exam2/issues/886
testImplementation("org.ops4j.pax.exam:pax-exam-testng:4.13.5")
testImplementation("org.ops4j.pax.exam:pax-exam-link-mvn:4.13.5")
testImplementation("org.ops4j.pax.url:pax-url-aether:2.6.12")
testImplementation("org.apache.felix:org.apache.felix.framework:7.0.5")
testImplementation("ch.qos.logback:logback-core:1.4.11")
testImplementation("ch.qos.logback:logback-classic:1.4.11")
}
// <editor-fold defaultstate="collapsed" desc="Pass dependency versions to pax-exam container">
val depDir = layout.buildDirectory.dir("pax-dependencies")
val generateDependenciesProperties by tasks.registering(WriteProperties::class) {
description = "Generates dependencies.properties so pax-exam can use .versionAsInProject()"
destinationFile.set(depDir.map { it.file("META-INF/maven/dependencies.properties") })
property("groupId", project.group)
property("artifactId", project.name)
property("version", project.version)
property("${project.group}/${project.name}/version", "${project.version}")
dependsOn(configurations.testRuntimeClasspath)
dependsOn(testngRepository)
doFirst {
configurations.testRuntimeClasspath.get().resolvedConfiguration.resolvedArtifacts.forEach {
val prefix = "${it.moduleVersion.id.group}/${it.moduleVersion.id.name}"
property("$prefix/scope", "compile")
property("$prefix/type", it.extension.orEmpty())
property("$prefix/version", it.moduleVersion.id.version)
}
}
}
sourceSets.test {
output.dir(mapOf("builtBy" to generateDependenciesProperties), depDir)
}
// </editor-fold>
// This repository is used instead of ~/.m2/... to avoid clash with /.m2/ contents
val paxLocalCacheRepository = layout.buildDirectory.dir("pax-repo")
val cleanCachedTestng by tasks.registering(Delete::class) {
description =
"Removes cached testng.jar from pax-repo folder so pax-exam always resolves the recent one"
delete(paxLocalCacheRepository.map { it.dir("org/testng") })
}
tasks.test {
dependsOn(generateDependenciesProperties)
dependsOn(cleanCachedTestng)
dependsOn(testngRepository)
systemProperty("logback.configurationFile", file("src/test/resources/logback-test.xml"))
// Regular systemProperty can't be used here as we need lazy evaluation of testngRepository
jvmArgumentProviders.add(CommandLineArgumentProvider {
listOf(
"-Dtestng.org.ops4j.pax.url.mvn.repositories=" +
"file:${testngRepository.singleFile.absolutePath}@snapshots@id=testng-current" +
",${project.findProperty("osgi.test.mavencentral.url")}@id=central",
"-Dtestng.org.ops4j.pax.url.mvn.localRepository=file:${paxLocalCacheRepository.get().asFile.absolutePath}@id=pax-repo"
)
})
ignoreFailures = true
}