Repository: apollographql/apollo-kotlin
Pull request #5120 (2023-07-24 11:50:20)

Add `./gradle ft`
`ft` is for `fast test`. It'll run the JVM tests except the Gradle one and is faster to iterate during development

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *apollo-android-docs* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 497b7f9e6d87b84e9ce8febadd38618c1d0c1ebd |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-android-docs/deploys/64be657fb68fb50008077044 |

Patch:
diff --git a/build-logic/src/main/kotlin/Common.kt b/build-logic/src/main/kotlin/Common.kt
new file mode 100644
index 0000000000..c4dd569149
--- /dev/null
+++ b/build-logic/src/main/kotlin/Common.kt
@@ -0,0 +1,22 @@
+
+import org.gradle.api.Project
+import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
+
+fun Project.commonSetup() {
+  pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
+    tasks.register("ft") {
+      if (this@commonSetup.name != "apollo-gradle-plugin") {
+        dependsOn("test")
+      }
+    }
+  }
+  pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
+    val fastTest = tasks.register("ft")
+
+    tasks.withType(KotlinJvmTest::class.java) {
+      fastTest.configure {
+        this.dependsOn(this@withType)
+      }
+    }
+  }
+}
diff --git a/build-logic/src/main/kotlin/CompilerOptions.kt b/build-logic/src/main/kotlin/CompilerOptions.kt
index f80c00c910..34d607d1d0 100644
--- a/build-logic/src/main/kotlin/CompilerOptions.kt
+++ b/build-logic/src/main/kotlin/CompilerOptions.kt
@@ -6,7 +6,6 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
 import org.gradle.jvm.toolchain.JavaToolchainService
 import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
 import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
-import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
 import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
 
 fun Project.configureJavaAndKotlinCompilers() {
diff --git a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
index 1030b85fac..b730599fbf 100644
--- a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
+++ b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
@@ -1,5 +1,6 @@
 package com.apollographql.apollo3.buildlogic.plugin
 
+import commonSetup
 import configureJavaAndKotlinCompilers
 import configureMppDefaults
 import configurePublishing
@@ -19,6 +20,7 @@ class LibraryConventionPlugin : Plugin<Project> {
       group = property("GROUP")!!
       version = property("VERSION_NAME")!!
 
+      commonSetup()
       extensions.create("apolloLibrary", Extension::class.java, project)
 
       configureJavaAndKotlinCompilers()
diff --git a/docs/source/advanced/java.mdx b/docs/source/advanced/java.mdx
index ebd34978d0..db75ee52af 100644
--- a/docs/source/advanced/java.mdx
+++ b/docs/source/advanced/java.mdx
@@ -16,33 +16,61 @@ apollo {
 }
 ```
 
-## Build the client
+## The Java runtime
 
-This snippet demonstrates initializing an `ApolloClient` instance in Java:
+The default runtime for Apollo Kotlin, `apollo-runtime`, exposes a coroutines / Flow-based API that isn't well suited to be consumed from Java.
+That is why a specific runtime, `apollo-runtime-java` is available to use Apollo Kotlin from Java. To use it, add a dependency on this runtime instead of the default one:
+
+```kotlin title="build.gradle[.kts]"
+dependencies {
+  // ...
+
+  // Use apollo-runtime-java instead of apollo-runtime
+  implementation("com.apollographql.apollo3:apollo-runtime-java:4.0.0-alpha.2")
+}
+```
+
+The Java runtime has a callbacks based API. This snippet demonstrates initializing and using an `ApolloClient` in Java:
 
 ```java
-import com.apollographql.apollo3.cache.normalized.NormalizedCache;
-import com.apollographql.apollo3.cache.http.HttpCache;
+import com.apollographql.apollo3.runtime.java.ApolloClient;
 // (...)
 
-ApolloClient.Builder builder = new ApolloClient.Builder()
+ApolloClient client = ApolloClient.Builder builder = new ApolloClient.Builder()
   .serverUrl("http://localhost:4000/graphql")
+  .build();
 
-// Optionally, set an http cache
-HttpCache.configureApolloClientBuilder(builder, cacheDirectory, cacheMaxSize);
+// Use enqueue to execute a query asynchronously
+apolloClient.query(new GetRandomQuery()).enqueue(response -> {
+  if (response.data != null) {
+    // No errors
+    System.out.println(response.data);
+  } else {
+    // Errors
+    if (response.exception instanceof ApolloGraphQLException) {
+      // GraphQL errors
+      System.out.println(((ApolloGraphQLException) response.exception).getErrors().get(0));
+    } else {
+      // Network error
+      response.exception.printStackTrace();
+    }
+  }
+});
+```
+
+Note that as of now, the Java runtime doesn't support the Http or Normalized caches.
 
-// Optionally, set a normalized cache
-NormalizedCache.configureApolloClientBuilder(
-  builder,
-  new MemoryCacheFactory(10 * 1024 * 1024, -1),
-  TypePolicyCacheKeyGenerator.INSTANCE,
-  FieldPolicyCacheResolver.INSTANCE,
-  false
-);
+### Cancelling requests
+
+`euqueue` returns an `ApolloDisposable` that can be used to cancel the request:
+
+```java
+ApolloDisposable disposable = apolloClient.subscription(new MyQuery()).enqueue(response -> ...)
+// ...
+disposable.dispose();
 
-ApolloClient client = builder.build();
 ```
 
-## Use RxJava extensions
+### RxJava extensions
 
-Apollo Kotlin has a coroutines / Flow-based API that isn't well suited to using with Java. To achieve a similar effect, you can use Apollo's [RxJava extensions](./rxjava/).
+If your project uses RxJava, you can use Apollo's [RxJava extensions](./rxjava/) with the Java runtime.
diff --git a/docs/source/advanced/rxjava.mdx b/docs/source/advanced/rxjava.mdx
index 2ceaf7d1bc..56d4ccbb3e 100644
--- a/docs/source/advanced/rxjava.mdx
+++ b/docs/source/advanced/rxjava.mdx
@@ -2,9 +2,23 @@
 title: RxJava support
 ---
 
-If you're using Apollo Kotlin in a [Java project](java) or a Kotlin project that uses RxJava, you can use Apollo's RxJava extensions.
+If you're using Apollo Kotlin in a [Java project](java) or Kotlin project that uses RxJava, you can use Apollo's RxJava extensions.
 
-To do so, add the `apollo-rx2-support` or `apollo-rx3-support` dependency to your project:
+To do so, add the `apollo-rx2-support-java` / `apollo-rx3-support-java` (Java) or `apollo-rx2-support` / `apollo-rx3-support` (Kotlin) dependency to your project:
+
+<MultiCodeBlock>
+
+```java title="build.gradle[.kts]"
+dependencies {
+  // ...
+
+  // For RxJava 2
+  implementation("com.apollographql.apollo3:apollo-rx2-support-java:4.0.0-alpha.2")
+
+  // For RxJava 3
+  implementation("com.apollographql.apollo3:apollo-rx3-support-java:4.0.0-alpha.2")
+}
+```
 
 ```kotlin title="build.gradle[.kts]"
 dependencies {
@@ -18,30 +32,35 @@ dependencies {
 }
 ```
 
+</MultiCodeBlock>
+
+
 ## Executing operations
 
-Use the `rxSingle` / `rxFlowable` extensions to execute GraphQL operations and get RxJava observables:
+In Java, Use the `Rx2Apollo` or `Rx3Apollo` classes to execute GraphQL operations and get RxJava observables.
+
+In Kotlin, use the `rxSingle()` / `rxFlowable()` extensions.
 
 <MultiCodeBlock>
 
 ```java
-import com.apollographql.apollo3.rx2.Rx2Apollo;
+import com.apollographql.apollo3.rx3.java.Rx3Apollo;
 
 // (...)
 
 // Query
 ApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());
-Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx2Apollo.single(queryCall);
+Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx3Apollo.single(queryCall);
 queryResponse.subscribe( /* ... */ );
 
 // Mutation
 ApolloCall<MyMutation.Data> mutationCall = client.mutation(new MyMutation("my-parameter"));
-Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx2Apollo.single(mutationCall);
+Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx3Apollo.single(mutationCall);
 mutationResponse.subscribe( /* ... */ );
 
 // Subscription
 ApolloCall<MySubscription.Data> subscriptionCall = client.subscription(new MySubscription());
-Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx2Apollo.flowable(subscriptionCall);
+Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx3Apollo.flowable(subscriptionCall);
 subscriptionResponse.subscribe( /* ... */ );
 ```
 
diff --git a/intellij-plugin/build.gradle.kts b/intellij-plugin/build.gradle.kts
index df14323ab3..e247925716 100644
--- a/intellij-plugin/build.gradle.kts
+++ b/intellij-plugin/build.gradle.kts
@@ -12,6 +12,8 @@ plugins {
   id("maven-publish")
 }
 
+commonSetup()
+
 // XXX: this should use the settings repositories instead
 repositories {
   // Uncomment this one to use the Kotlin "dev" repository


Test patch:
diff --git a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
index 2ba2831a79..e8b72bd489 100644
--- a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
+++ b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
@@ -1,5 +1,6 @@
 package com.apollographql.apollo3.buildlogic.plugin
 
+import commonSetup
 import configureJavaAndKotlinCompilers
 import configureMppTestsDefaults
 import configureTesting
@@ -16,6 +17,7 @@ class TestConventionPlugin : Plugin<Project> {
     with(project) {
       extensions.create("apolloTest", Extension::class.java)
 
+      commonSetup()
       configureJavaAndKotlinCompilers()
       optIn(
           "com.apollographql.apollo3.annotations.ApolloExperimental",