|
| 1 | +import org.gradle.api.Project |
| 2 | +import org.gradle.api.JavaVersion |
| 3 | +import org.gradle.api.plugins.JavaPluginExtension |
| 4 | +import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferPlugin |
| 5 | + |
| 6 | +initscript { |
| 7 | + repositories { |
| 8 | + gradlePluginPortal() |
| 9 | + mavenCentral() |
| 10 | + } |
| 11 | + dependencies { |
| 12 | + classpath("ru.vyarus:gradle-animalsniffer-plugin:2.0.1") |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +val excludedPathPrefixes = |
| 17 | + setOf( |
| 18 | + ":sentry-samples", |
| 19 | + ":sentry-system-test-support", |
| 20 | + ":sentry-test-support", |
| 21 | + ) |
| 22 | + |
| 23 | +fun Project.isJava8SdkModule(): Boolean { |
| 24 | + val java = extensions.findByType(JavaPluginExtension::class.java) ?: return false |
| 25 | + return plugins.hasPlugin("java-library") && |
| 26 | + java.targetCompatibility == JavaVersion.VERSION_1_8 && |
| 27 | + excludedPathPrefixes.none { path == it || path.startsWith("$it:") } |
| 28 | +} |
| 29 | + |
| 30 | +allprojects { |
| 31 | + if (rootProject.name != "sentry-root") return@allprojects |
| 32 | + |
| 33 | + afterEvaluate { |
| 34 | + if (!isJava8SdkModule()) return@afterEvaluate |
| 35 | + |
| 36 | + if (!plugins.hasPlugin("ru.vyarus.animalsniffer")) { |
| 37 | + apply<AnimalSnifferPlugin>() |
| 38 | + } |
| 39 | + |
| 40 | + configurations.named("signature").configure { |
| 41 | + dependencies.clear() |
| 42 | + } |
| 43 | + dependencies.add("signature", "org.codehaus.mojo.signature:java18:1.0@signature") |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +rootProject { |
| 48 | + tasks.register("java8ApiCompatibility") { |
| 49 | + group = "verification" |
| 50 | + description = "Checks Java 8 SDK modules against the Java 8 runtime API signature." |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +gradle.projectsEvaluated { |
| 55 | + val java8SdkModules = rootProject.allprojects.filter { it.isJava8SdkModule() } |
| 56 | + rootProject.tasks.named("java8ApiCompatibility").configure { |
| 57 | + dependsOn(java8SdkModules.map { it.tasks.named("animalsnifferMain") }) |
| 58 | + doFirst { |
| 59 | + logger.lifecycle( |
| 60 | + "Checking Java 8 API compatibility for: ${java8SdkModules.joinToString { it.path }}" |
| 61 | + ) |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments