Skip to content

Switch the gradle plugin to gratatouille #6524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
runtimeOnly(libs.sqldelight.plugin)
runtimeOnly(libs.gradle.publish.plugin)
runtimeOnly(libs.benmanes.versions)
runtimeOnly(libs.gr8)
runtimeOnly(libs.gratatouille)
runtimeOnly(libs.kotlinx.binarycompatibilityvalidator)
}

Expand Down
8 changes: 0 additions & 8 deletions build-logic/src/main/kotlin/CompilerOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptio
allWarningsAsErrors(true)
}

fun setTestToolchain(project: Project, test: Test, javaVersion: Int) {
val javaToolchains = project.extensions.getByName("javaToolchains") as JavaToolchainService
test.javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
})

}

fun Project.allWarningsAsErrors(allWarningsAsErrors: Boolean) {
kotlinExtensionOrNull?.forEachCompilerOptions {
this.allWarningsAsErrors.set(allWarningsAsErrors)
Expand Down
6 changes: 0 additions & 6 deletions build-logic/src/main/kotlin/Publishing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,6 @@ private fun Project.configurePublishingInternal() {
}
}

plugins.hasPlugin("com.gradle.plugin-publish") -> {
/**
* com.gradle.plugin-publish creates all publications
*/
}

plugins.hasPlugin("java-gradle-plugin") -> {
/**
* java-gradle-plugin creates 2 publications (one marker and one regular) but without source/javadoc.
Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ tasks.register("ciPublishRelease") {

tasks.register("ciTestsGradle") {
description = "Execute the Gradle tests (slow)"
dependsOn(":apollo-gradle-plugin:allTests")
dependsOn(":apollo-gradle-plugin-external:validatePlugins")
dependsOn(":apollo-gradle-plugin:test")
}

tasks.register("ciTestsNoGradle") {
Expand Down
2 changes: 1 addition & 1 deletion docs/source/advanced/persisted-queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ apollo {

The operation manifest is generated during code generation. This happens automatically every time you build your project, or you can trigger it manually by executing the `generateApolloSources` Gradle task.

The operation manifest is generated in `build/generated/manifest/apollo/$serviceName/persistedQueryManifest.json`, where `$serviceName` is `"api"` here. The resulting operation manifest looks something like this:
The operation manifest is generated in `build/generated/manifest/apollo/$serviceName/persistedQueryManifest.json`, where `$serviceName` is `"api"` here. The resulting operation manifest is similar to the following example:

```json title="persistedQueryManifest.json"
{
Expand Down
12 changes: 3 additions & 9 deletions docs/source/advanced/plugin-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apollo {

For more advanced usages, below are all Apollo Gradle Plugin options in a single code block. You can also take a look at the [Gradle Plugin recipes](../advanced/plugin-recipes).

Please refer to the [ApolloExtension](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo.gradle.api/-apollo-extension/index.html) and [Service](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo.gradle.api/-service/index.html) API reference for details about a specific API.
Refer to the [ApolloExtension](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin/com.apollographql.apollo.gradle.api/-apollo-extension/index.html) and [Service](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin/com.apollographql.apollo.gradle.api/-service/index.html) API reference for details about each API.

```kotlin
apollo {
Expand Down Expand Up @@ -70,10 +70,8 @@ apollo {
mapScalarToJavaObject("MyObject")


// The format to output for the operation manifest. One of "operationOutput", "persistedQueryManifest"
// The format to output for the operation manifest. One of "none" (default) or "persistedQueryManifest"
operationManifestFormat.set("persistedQueryManifest")
// The file where to write the operation manifest
operationManifest.set(file("build/generated/persistedQueryManifest.json"))

// Whether to generate Kotlin or Java models
generateKotlinModels.set(true)
Expand Down Expand Up @@ -123,11 +121,7 @@ apollo {
classesForEnumsMatching.set(listOf(".*"))
// Whether fields with different shape are disallowed to be merged in disjoint types.
fieldsOnDisjointTypesMustMerge.set(false)


// The directory where the generated models are written.
outputDir.set(file("build/generated/apollo"))


// Whether to generate Apollo metadata. Apollo metadata is used for multi-module support.
generateApolloMetadata.set(true)
// list of [Regex] patterns matching for types and fields that should be generated whether they are used by queries/fragments in this module or not.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/caching/declarative-ids.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extend interface Node @typePolicy(keyFields: "id")

## Adding `__typename` to your operations

In addition to the key fields, the declarative cache requires the `__typename` of each object by default. These typenames are not included by default as they make query larger for non-cache users. To avoid cache misses, add `__typename` to every selection using [addTypename](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo.gradle.api/-service/add-typename.html):
In addition to the key fields, the declarative cache requires the `__typename` of each object by default. These typenames are not included by default because they make the queries larger for users not using the cache. To avoid cache misses, add `__typename` to every selection using [addTypename](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin/com.apollographql.apollo.gradle.api/-service/add-typename.html):

```kotlin
apollo {
Expand Down
2 changes: 1 addition & 1 deletion docs/source/caching/programmatic-ids.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

Note that for cache ID generation to work, your GraphQL operations must return whatever fields your custom code relies on (such as `id` above). If a query does not return a required field, the cache ID will be inconsistent, resulting in data duplication.
Also, for interfaces and unions, `context.field.type.rawType().name` yields the typename as it is declared in the schema, as opposed to the runtime value of the type received in the response. Instead, querying for the `__typename` is safer.
To make sure `__typename` is included in all operations set the [addTypename](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo.gradle.api/-service/add-typename.html) gradle config:
To make sure `__typename` is included in all operations set the [addTypename](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin/com.apollographql.apollo.gradle.api/-service/add-typename.html) gradle config:

Check warning on line 58 in docs/source/caching/programmatic-ids.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/caching/programmatic-ids.mdx#L58

Use "ensure" for a more formal tone than "make sure." Use "Gradle setting" for a more professional term than "gradle config." Link text for code symbols like configuration options should use code font. ```suggestion To ensure <code>__typename</code> is included in all operations, set the [<code>addTypename</code>](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin/com.apollographql.apollo.gradle.api/-service/add-typename.html) Gradle setting: ```

```
apollo {
Expand Down
14 changes: 3 additions & 11 deletions docs/source/essentials/modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,13 @@

`apollo-gradle-plugin` contains the Apollo Gradle plugin.

This module shadows and relocates its runtime dependencies to avoid classpath issues. This can make debugging harder in some cases.

See `apollo-gradle-plugin-external` for a version of `apollo-gradle-plugin` that does not shadow its dependencies.

See ["Gradle Plugin Configuration"](https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration/) for how to use the Gradle plugin.

### apollo-gradle-plugin-external

`apollo-gradle-plugin-external` contains the Apollo Gradle plugin.
### apollo-gradle-plugin-tasks

Check warning on line 53 in docs/source/essentials/modules.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/essentials/modules.mdx#L53

For reference headings that are specific code-related terms (like module names), use code font for clarity and consistency with how these terms are styled in body text. The term itself acts as the noun heading. ```suggestion ### <code>apollo-gradle-plugin-tasks</code> ```

This module does not shadow its runtime dependencies, making it more prone to Gradle classpath issues.
`apollo-gradle-plugin-tasks` contains the task implementations for the Apollo Gradle plugin.

See `apollo-gradle-plugin` for a version of `apollo-gradle-plugin-external` that shadow its dependencies.

See ["Gradle Plugin Configuration"](https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration/) for how to use the Gradle plugin.
This module is loaded in a separate classloader to allow compiler plugins and avoid polluting the main build script classpath. This module is an implementation detail of `apollo-gradle-plugin` and should not be depended on directly.

Check warning on line 57 in docs/source/essentials/modules.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/essentials/modules.mdx#L57

Use "enable" instead of "allow" when referring to functionality a feature provides. Use active voice ("Do not depend on it directly") for clarity and directness, instead of passive voice ("should not be depended on directly"). ```suggestion This module is loaded in a separate classloader to enable compiler plugins and avoid polluting the main build script classpath. This module is an implementation detail of <code>apollo-gradle-plugin</code>. Do not depend on it directly. ```

### apollo-http-cache

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ org.jetbrains.dokka.experimental.tryK2.nowarn=true

# https://kotlinlang.slack.com/archives/C0B8L3U69/p1740063113894839
kotlin.js.yarn=false

# https://github.com/gradle/gradle/issues/31278
kotlin.internal.collectFUSMetrics=false
4 changes: 3 additions & 1 deletion gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ atomicfu = "0.26.0"
compat-patrouille = "0.0.0"
compose = "1.5.1"
guava = "31.1-jre"
gratatouille = "0.0.10"
javaPoet = "1.13.0"
jetbrains-annotations = "24.0.1"
junit = "4.13.2"
Expand Down Expand Up @@ -97,7 +98,8 @@ dgp = "com.gradle:develocity-gradle-plugin:4.0.2" # // sync with settings.gradle
# annotation @org.jetbrains.annotations.Nullable not applicable in this type context
google-testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version = "0.19" }
google-testparameterinjector = { group = "com.google.testparameterinjector", name = "test-parameter-injector", version = "1.11" }
gr8 = { group = "com.gradleup", name = "gr8-plugin", version = "0.11.1" }
gratatouille = { group = "com.gradleup.gratatouille", name = "gratatouille-gradle-plugin", version.ref = "gratatouille" }

#
# See https://github.com/gradle/gradle/issues/1835
# We use the Nokee[redistributed artifacts](https://docs.nokee.dev/manual/gradle-plugin-development.html#sec:gradle-dev-redistributed-gradle-api)
Expand Down
8 changes: 2 additions & 6 deletions intellij-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ apollo {
}
}

// We're using project(":apollo-gradle-plugin-external") and the published "apollo-runtime" which do not have the same version
// We're using project(":apollo-gradle-plugin") and the published "apollo-runtime" which do not have the same version
tasks.configureEach {
if (name == "checkApolloVersions") {
enabled = false
Expand All @@ -171,11 +171,7 @@ dependencies {
zipSigner()
}

// Coroutines must be excluded to avoid a conflict with the version bundled with the IDE
// See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#coroutinesLibraries
implementation(project(":apollo-gradle-plugin-external")) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
}
implementation(project(":apollo-gradle-plugin"))
implementation(project(":apollo-ast"))
implementation(project(":apollo-tooling")) {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
Expand Down
38 changes: 13 additions & 25 deletions libraries/apollo-compiler/api/apollo-compiler.api
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public final class com/apollographql/apollo/compiler/ApolloCompiler {
}

public abstract interface class com/apollographql/apollo/compiler/ApolloCompiler$Logger {
public abstract fun debug (Ljava/lang/String;)V
public abstract fun error (Ljava/lang/String;)V
public abstract fun info (Ljava/lang/String;)V
public abstract fun warning (Ljava/lang/String;)V
}

Expand All @@ -36,9 +39,9 @@ public abstract interface class com/apollographql/apollo/compiler/ApolloCompiler
}

public final class com/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment {
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;)V
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;)V
public final fun getArguments ()Ljava/util/Map;
public final fun getLogger ()Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;
public final fun getLogger ()Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;
}

public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerPluginLogger {
Expand Down Expand Up @@ -203,12 +206,12 @@ public abstract interface class com/apollographql/apollo/compiler/DocumentTransf
}

public final class com/apollographql/apollo/compiler/EntryPoints {
public fun <init> ()V
public final fun buildCodegenSchema (Ljava/util/Map;IZLjava/util/List;Ljava/util/function/Consumer;Ljava/io/File;Ljava/io/File;)V
public final fun buildDataBuilders (Ljava/util/Map;IZLjava/util/List;Ljava/util/List;Ljava/util/Map;Ljava/io/File;Ljava/io/File;)V
public final fun buildIr (Ljava/util/Map;ILjava/util/List;Ljava/util/List;Ljava/util/List;Ljava/io/File;Ljava/util/function/Consumer;Ljava/io/File;)V
public final fun buildSources (Ljava/util/Map;IZLjava/util/List;Ljava/util/List;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/util/function/Consumer;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V
public final fun buildSourcesFromIr (Ljava/util/Map;IZLjava/util/List;Ljava/util/List;Ljava/io/File;Ljava/util/Map;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V
public static final field INSTANCE Lcom/apollographql/apollo/compiler/EntryPoints;
public final fun buildCodegenSchema (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;ZLjava/util/List;Ljava/io/File;Ljava/io/File;)V
public final fun buildDataBuilders (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;ZLjava/util/List;Ljava/util/List;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V
public final fun buildIr (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;ZLjava/util/List;Ljava/util/List;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public final fun buildSources (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;ZLjava/util/List;Ljava/util/List;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V
public final fun buildSourcesFromIr (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;ZLjava/util/List;Ljava/util/List;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;Ljava/io/File;)V
}

public final class com/apollographql/apollo/compiler/EntrypointsKt {
Expand Down Expand Up @@ -250,6 +253,7 @@ public final class com/apollographql/apollo/compiler/FileUtils {
public static final fun readIrSchema (Ljava/io/File;)Lcom/apollographql/apollo/compiler/ir/IrSchema;
public static final fun readOperationOutput (Ljava/io/File;)Ljava/util/Map;
public static final fun readPersistedQueryManifest (Ljava/io/File;)Lcom/apollographql/apollo/compiler/pqm/PersistedQueryManifest;
public static final fun toUsedCoordinates (Ljava/io/File;)Lcom/apollographql/apollo/compiler/UsedCoordinates;
public static final fun writeCodegenMetadata (Lcom/apollographql/apollo/compiler/CodegenMetadata;Ljava/io/File;)V
public static final fun writeCodegenOptions (Lcom/apollographql/apollo/compiler/CodegenOptions;Ljava/io/File;)V
public static final fun writeCodegenSchema (Lcom/apollographql/apollo/compiler/CodegenSchema;Ljava/io/File;)V
Expand All @@ -259,6 +263,7 @@ public final class com/apollographql/apollo/compiler/FileUtils {
public static final fun writeIrSchema (Lcom/apollographql/apollo/compiler/ir/IrSchema;Ljava/io/File;)V
public static final fun writeOperationOutput (Ljava/util/Map;Ljava/io/File;)V
public static final fun writePersistedQueryManifest (Lcom/apollographql/apollo/compiler/pqm/PersistedQueryManifest;Ljava/io/File;)V
public static final fun writeTo (Lcom/apollographql/apollo/compiler/UsedCoordinates;Ljava/io/File;)V
}

public final class com/apollographql/apollo/compiler/GeneratedMethod : java/lang/Enum {
Expand Down Expand Up @@ -666,23 +671,6 @@ public final class com/apollographql/apollo/compiler/codegen/kotlin/helpers/Add_
public static final fun addInternal (Lcom/squareup/kotlinpoet/FileSpec$Builder;Ljava/util/List;)Lcom/squareup/kotlinpoet/FileSpec$Builder;
}

public final class com/apollographql/apollo/compiler/internal/GradleCompilerPluginLogger : com/apollographql/apollo/compiler/ApolloCompilerPluginLogger {
public static final field Companion Lcom/apollographql/apollo/compiler/internal/GradleCompilerPluginLogger$Companion;
public static final field LOGGING_LEVEL_ERROR I
public static final field LOGGING_LEVEL_INFO I
public static final field LOGGING_LEVEL_LOGGING I
public static final field LOGGING_LEVEL_WARN I
public fun <init> (I)V
public fun error (Ljava/lang/String;)V
public final fun getLoglevel ()I
public fun info (Ljava/lang/String;)V
public fun logging (Ljava/lang/String;)V
public fun warn (Ljava/lang/String;)V
}

public final class com/apollographql/apollo/compiler/internal/GradleCompilerPluginLogger$Companion {
}

public final class com/apollographql/apollo/compiler/ir/BLabel : com/apollographql/apollo/compiler/ir/BTerm {
public fun <init> (Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ import java.io.File

object ApolloCompiler {
interface Logger {
fun debug(message: String)
fun info(message: String)
fun warning(message: String)
fun error(message: String)
}

fun buildCodegenSchema(
Expand Down Expand Up @@ -412,19 +415,16 @@ object ApolloCompiler {
""".trimMargin()
}

val operationManifestFormat = codegenOptions.operationManifestFormat
if ((operationManifestFormat ?: defaultOperationManifestFormat) != MANIFEST_NONE) {
check(operationManifestFile != null) {
"Apollo: no operationManifestFile set to output '$operationManifestFormat' operation manifest"
}
if (operationManifestFile != null) {
val operationManifestFormat = codegenOptions.operationManifestFormat
@Suppress("DEPRECATION_ERROR")
when (operationManifestFormat) {
MANIFEST_NONE -> operationManifestFile.writeText("Use operationManifestFormat to generate the operation manifest.")
MANIFEST_OPERATION_OUTPUT -> operationOutput.writeTo(operationManifestFile)
MANIFEST_PERSISTED_QUERY -> operationOutput.toPersistedQueryManifest().writeTo(operationManifestFile)
}
}


@Suppress("NAME_SHADOWING")
val layout = layout ?: SchemaAndOperationsLayout(
codegenSchema = codegenSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ApolloCompilerPluginEnvironment(
/**
* A logger that can be used by the plugin.
*/
val logger: ApolloCompilerPluginLogger,
val logger: ApolloCompiler.Logger,
)

/**
Expand Down
Loading
Loading