Skip to content

Commit

Permalink
Switch back to the kotlin JVM plugin
Browse files Browse the repository at this point in the history
This does a ton of file moves from jvmMain to main, and jvmTest to test.
  • Loading branch information
squarejesse committed Dec 19, 2023
1 parent 6b7b611 commit aea3b35
Show file tree
Hide file tree
Showing 375 changed files with 132 additions and 256 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: check -PandroidBuild=true -PgraalBuild=true -x test -x jvmTest
arguments: check -PandroidBuild=true -PgraalBuild=true -x test -x test

testopenjdk11:
permissions:
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=11
arguments: test -Dtest.java.version=11

- name: Publish Test Report
if: github.repository == 'square/okhttp' && github.ref == 'refs/heads/master'
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=11
arguments: test -Dtest.java.version=11

testopenjdk8:
runs-on: ubuntu-latest
Expand All @@ -169,7 +169,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8
arguments: test -Dtest.java.version=8

testopenjdk8alpn:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -202,7 +202,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8 -Dokhttp.platform=jdk8alpn -Dalpn.boot.version=8.1.13.v20181017 -Dorg.gradle.java.installations.paths=/opt/hostedtoolcache/Java_Adopt_jdk/8.0.242-8.1/x64
arguments: test -Dtest.java.version=8 -Dokhttp.platform=jdk8alpn -Dalpn.boot.version=8.1.13.v20181017 -Dorg.gradle.java.installations.paths=/opt/hostedtoolcache/Java_Adopt_jdk/8.0.242-8.1/x64

testopenjsse:
runs-on: ubuntu-latest
Expand All @@ -229,7 +229,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=8 -Dokhttp.platform=openjsse
arguments: test -Dtest.java.version=8 -Dokhttp.platform=openjsse

testconscrypt:
runs-on: ubuntu-latest
Expand All @@ -256,7 +256,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=conscrypt
arguments: test -Dokhttp.platform=conscrypt

testbouncycastle:
runs-on: ubuntu-latest
Expand All @@ -283,7 +283,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=bouncycastle
arguments: test -Dokhttp.platform=bouncycastle

testcorretto:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -311,7 +311,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=corretto
arguments: test -Dokhttp.platform=corretto

testopenjdk17:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -339,7 +339,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=17
arguments: test -Dtest.java.version=17

testopenjdk19:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -373,7 +373,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dtest.java.version=19
arguments: test -Dtest.java.version=19

testwindows:
runs-on: windows-latest
Expand Down Expand Up @@ -401,7 +401,7 @@ jobs:
- name: Test
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest
arguments: test

testgraal:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -532,7 +532,7 @@ jobs:
- name: Run Checks
uses: gradle/gradle-build-action@v2
with:
arguments: jvmTest -Dokhttp.platform=loom -Dtest.java.version=20
arguments: test -Dokhttp.platform=loom -Dtest.java.version=20


testandroidregression:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ limitations under the License.
[conscrypt]: https://github.com/google/conscrypt/
[get_example]: https://raw.github.com/square/okhttp/master/samples/guide/src/main/java/okhttp3/guide/GetExample.java
[kotlin]: https://kotlinlang.org/
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro
[okhttp_312x]: https://github.com/square/okhttp/tree/okhttp_3.12.x
[okhttp]: https://square.github.io/okhttp/
[okio]: https://github.com/square/okio
Expand Down
46 changes: 1 addition & 45 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import groovy.util.Node
import groovy.util.NodeList
import java.net.URL
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension

Expand Down Expand Up @@ -179,16 +174,9 @@ subprojects {
}

// https://publicobject.com/2023/04/16/read-a-project-file-in-a-kotlin-multiplatform-test/
tasks.withType<KotlinJvmTest>().configureEach {
tasks.withType<Test>().configureEach {
environment("OKHTTP_ROOT", rootDir)
}
tasks.withType<KotlinNativeTest>().configureEach {
environment("SIMCTL_CHILD_OKHTTP_ROOT", rootDir)
environment("OKHTTP_ROOT", rootDir)
}
tasks.withType<KotlinJsTest>().configureEach {
environment("OKHTTP_ROOT", rootDir.toString())
}

if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
Expand Down Expand Up @@ -265,31 +253,6 @@ subprojects {
}
}
}

// Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
// This hack allows Maven users to continue using our original OkHttp artifact names (like
// com.squareup.okhttp3:okhttp:5.x.y) even though we changed that artifact from JVM-only
// to Kotlin Multiplatform. Note that module.json doesn't need this hack.
val mavenPublications = publishingExtension.publications.withType<MavenPublication>()
mavenPublications.configureEach {
if (name != "jvm") return@configureEach
val jvmPublication = this
val kmpPublication = mavenPublications.getByName("kotlinMultiplatform")
kmpPublication.pom.withXml {
val root = asNode()
val dependencies = (root["dependencies"] as NodeList).firstOrNull() as Node?
?: root.appendNode("dependencies")
for (child in dependencies.children().toList()) {
dependencies.remove(child as Node)
}
dependencies.appendNode("dependency").apply {
appendNode("groupId", jvmPublication.groupId)
appendNode("artifactId", jvmPublication.artifactId)
appendNode("version", jvmPublication.version)
appendNode("scope", "compile")
}
}
}
}
}

Expand All @@ -304,13 +267,6 @@ subprojects {
ignoredPackages += "okhttp3.tls.internal"
}
}

plugins.withId("org.jetbrains.kotlin.jvm") {
val jvmTest by tasks.creating {
description = "Get 'gradlew jvmTest' to run the tests of JVM-only modules"
dependsOn("test")
}
}
}

tasks.wrapper {
Expand Down
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName

fun Project.applyOsgi(vararg bndProperties: String) {
// Configure OSGi for the JVM platform on kotlin-multiplatform.
plugins.withId("org.jetbrains.kotlin.multiplatform") {
applyOsgi("jvmJar", "jvmOsgiApi", bndProperties)
}

// Configure OSGi for kotlin-jvm.
plugins.withId("org.jetbrains.kotlin.jvm") {
applyOsgi("jar", "osgiApi", bndProperties)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/features/r8_proguard.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interpreted by R8 automatically.
If you, however, don't use R8 you have to apply the rules from [this file][okhttp3_pro]. You might
also need rules from [Okio][okio] which is a dependency of this library.

[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro
[okhttp3_pro]: https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro
[okio]: https://square.github.io/okio/
70 changes: 17 additions & 53 deletions okcurl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,65 +1,41 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.KotlinJvm
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
kotlin("multiplatform")
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("com.palantir.graal")
id("com.github.johnrengelman.shadow")
}

val copyResourcesTemplates = tasks.register<Copy>("copyResourcesTemplates") {
from("src/jvmMain/resources-templates")
from("src/main/resources-templates")
into("$buildDir/generated/resources-templates")
expand("projectVersion" to "${project.version}")
filteringCharset = Charsets.UTF_8.toString()
}

kotlin {
jvm()

sourceSets {
val jvmMain by getting {
val main by getting {
resources.srcDir(copyResourcesTemplates.get().outputs)
dependencies {
api(libs.kotlin.stdlib)
}
dependencies {
api(libs.kotlin.stdlib)
api(projects.okhttp)
api(projects.loggingInterceptor)
api(libs.squareup.okio)
implementation(libs.clikt)
api(libs.guava.jre)
}
}
}
}

val jvmTest by getting {
dependencies {
api(libs.kotlin.stdlib)
implementation(projects.okhttpTestingSupport)
api(libs.squareup.okio)
api(libs.assertk)
implementation(kotlin("test"))
}
}
dependencies {
api(libs.kotlin.stdlib)
api(projects.okhttp)
api(projects.loggingInterceptor)
api(libs.squareup.okio)
implementation(libs.clikt)
api(libs.guava.jre)

// Workaround for https://github.com/palantir/gradle-graal/issues/129
// Add a second configuration to populate
// runtimeClasspath vs jvmRuntimeClasspath
val main by register("main") {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(projects.okhttp)
implementation(projects.loggingInterceptor)
implementation(libs.squareup.okio)
implementation(libs.clikt)
implementation(libs.guava.jre)
}
}
}
testImplementation(projects.okhttpTestingSupport)
testApi(libs.assertk)
testImplementation(kotlin("test"))
}

tasks.jar {
Expand Down Expand Up @@ -89,18 +65,6 @@ graal {
}
}

// Workaround for https://github.com/palantir/gradle-graal/issues/129
// Copy the jvmJar output into the normal jar location
val copyJvmJar = tasks.register<Copy>("copyJvmJar") {
val sourceFile = project.tasks.getByName("jvmJar").outputs.files.singleFile
val destinationFile = project.tasks.getByName("jar").outputs.files.singleFile
from(sourceFile)
into(destinationFile.parentFile)
rename (sourceFile.name, destinationFile.name)
}
tasks.getByName("copyJvmJar").dependsOn(tasks.getByName("jvmJar"))
tasks.getByName("nativeImage").dependsOn(copyJvmJar)

mavenPublishing {
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty()))
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
}
File renamed without changes.
49 changes: 17 additions & 32 deletions okhttp-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.KotlinJvm

plugins {
kotlin("multiplatform")
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("binary-compatibility-validator")
}

kotlin {
jvm {
withJava()
}

sourceSets {
getByName("jvmMain") {
dependencies {
api(projects.okhttp)
implementation(libs.kotlinx.coroutines.core)
api(libs.squareup.okio)
api(libs.kotlin.stdlib)
}
}
getByName("jvmTest") {
dependencies {
implementation(libs.kotlin.test.common)
implementation(libs.kotlin.test.annotations)
api(libs.assertk)
implementation(projects.okhttpTestingSupport)
implementation(libs.kotlinx.coroutines.test)
implementation(projects.mockwebserver3Junit5)
}
}
}
}

project.applyOsgi(
"Export-Package: okhttp3.coroutines",
"Automatic-Module-Name: okhttp3.coroutines",
"Bundle-SymbolicName: com.squareup.okhttp3.coroutines"
)

dependencies {
api(projects.okhttp)
implementation(libs.kotlinx.coroutines.core)
api(libs.squareup.okio)
api(libs.kotlin.stdlib)

testImplementation(libs.kotlin.test.common)
testImplementation(libs.kotlin.test.annotations)
testApi(libs.assertk)
testImplementation(projects.okhttpTestingSupport)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(projects.mockwebserver3Junit5)
}

mavenPublishing {
configure(
KotlinMultiplatform(javadocJar = JavadocJar.Empty())
)
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
}
Loading

0 comments on commit aea3b35

Please sign in to comment.