openai/openai-java
Publicmirrored from https://github.com/openai/openai-javaAvailable
openai-java-proguard-test/build.gradle.kts
101lines · modecode
| 1 | plugins { |
| 2 | id("openai.kotlin") |
| 3 | id("com.gradleup.shadow") version "8.3.8" |
| 4 | } |
| 5 | |
| 6 | buildscript { |
| 7 | repositories { |
| 8 | google() |
| 9 | } |
| 10 | |
| 11 | dependencies { |
| 12 | classpath("com.guardsquare:proguard-gradle:7.4.2") |
| 13 | classpath("com.android.tools:r8:8.3.37") |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | dependencies { |
| 18 | testImplementation(project(":openai-java")) |
| 19 | testImplementation(kotlin("test")) |
| 20 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") |
| 21 | testImplementation("org.assertj:assertj-core:3.27.7") |
| 22 | testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0") |
| 23 | } |
| 24 | |
| 25 | tasks.shadowJar { |
| 26 | from(sourceSets.test.get().output) |
| 27 | configurations = listOf(project.configurations.testRuntimeClasspath.get()) |
| 28 | } |
| 29 | |
| 30 | val proguardJarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-proguard.jar" |
| 31 | val proguardJar by tasks.registering(proguard.gradle.ProGuardTask::class) { |
| 32 | group = "verification" |
| 33 | dependsOn(tasks.shadowJar) |
| 34 | notCompatibleWithConfigurationCache("ProGuard") |
| 35 | |
| 36 | injars(tasks.shadowJar) |
| 37 | outjars(proguardJarPath) |
| 38 | printmapping("${layout.buildDirectory.get()}/proguard-mapping.txt") |
| 39 | |
| 40 | val javaHome = System.getProperty("java.home") |
| 41 | if (System.getProperty("java.version").startsWith("1.")) { |
| 42 | // Before Java 9, the runtime classes were packaged in a single jar file. |
| 43 | libraryjars("$javaHome/lib/rt.jar") |
| 44 | } else { |
| 45 | // As of Java 9, the runtime classes are packaged in modular jmod files. |
| 46 | libraryjars( |
| 47 | // Filters must be specified first, as a map. |
| 48 | mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"), |
| 49 | "$javaHome/jmods/java.base.jmod" |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | configuration("./test.pro") |
| 54 | configuration("../openai-java-core/src/main/resources/META-INF/proguard/openai-java-core.pro") |
| 55 | } |
| 56 | |
| 57 | val testProGuard by tasks.registering(JavaExec::class) { |
| 58 | group = "verification" |
| 59 | dependsOn(proguardJar) |
| 60 | notCompatibleWithConfigurationCache("ProGuard") |
| 61 | |
| 62 | mainClass.set("com.openai.proguard.ProGuardCompatibilityTest") |
| 63 | classpath = files(proguardJarPath) |
| 64 | } |
| 65 | |
| 66 | val r8JarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-r8.jar" |
| 67 | val r8Jar by tasks.registering(JavaExec::class) { |
| 68 | group = "verification" |
| 69 | dependsOn(tasks.shadowJar) |
| 70 | notCompatibleWithConfigurationCache("R8") |
| 71 | |
| 72 | mainClass.set("com.android.tools.r8.R8") |
| 73 | classpath = buildscript.configurations["classpath"] |
| 74 | |
| 75 | args = listOf( |
| 76 | "--release", |
| 77 | "--classfile", |
| 78 | "--output", r8JarPath, |
| 79 | "--lib", System.getProperty("java.home"), |
| 80 | "--pg-conf", "./test.pro", |
| 81 | "--pg-conf", "../openai-java-core/src/main/resources/META-INF/proguard/openai-java-core.pro", |
| 82 | "--pg-map-output", "${layout.buildDirectory.get()}/r8-mapping.txt", |
| 83 | tasks.shadowJar.get().archiveFile.get().asFile.absolutePath, |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | val testR8 by tasks.registering(JavaExec::class) { |
| 88 | group = "verification" |
| 89 | dependsOn(r8Jar) |
| 90 | notCompatibleWithConfigurationCache("R8") |
| 91 | |
| 92 | mainClass.set("com.openai.proguard.ProGuardCompatibilityTest") |
| 93 | classpath = files(r8JarPath) |
| 94 | } |
| 95 | |
| 96 | tasks.test { |
| 97 | dependsOn(testProGuard) |
| 98 | dependsOn(testR8) |
| 99 | // We defer to the tests run via the ProGuard JAR. |
| 100 | enabled = false |
| 101 | } |
| 102 | |