From 4298dfa3db97d757062f34a2f67bc621ee72ec61 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Tue, 27 Jul 2021 11:04:12 +0200 Subject: [PATCH 1/2] add OutputDirConnection --- .../apollo3/gradle/api/AndroidProject.kt | 61 +--------- .../apollo3/gradle/api/ApolloExtension.kt | 4 +- .../apollo3/gradle/api/KotlinJvmProject.kt | 23 ---- .../gradle/api/KotlinMultiplatformProject.kt | 21 ---- .../apollo3/gradle/api/Service.kt | 106 +++++++++++++----- .../apollo3/gradle/api/project.kt | 42 ++++++- .../gradle/internal/DefaultApolloExtension.kt | 48 +++++--- .../internal/DefaultOutputDirConnection.kt | 75 +++++++++++++ .../apollo3/gradle/internal/DefaultService.kt | 12 +- .../apollo3/gradle/test/ServiceTests.kt | 11 +- .../kotlinJvmSourceSets/build.gradle.kts | 2 +- .../testSourceSet/build.gradle.kts | 5 +- .../essentials/60-plugin-configuration.mdx | 8 +- tests/integration-tests/build.gradle.kts | 13 +-- 14 files changed, 252 insertions(+), 179 deletions(-) delete mode 100644 apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinJvmProject.kt delete mode 100644 apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinMultiplatformProject.kt create mode 100644 apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/AndroidProject.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/AndroidProject.kt index 721ddb915cc..631f3013605 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/AndroidProject.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/AndroidProject.kt @@ -1,73 +1,24 @@ package com.apollographql.apollo3.gradle.api -import com.android.build.gradle.AppExtension -import com.android.build.gradle.BaseExtension -import com.android.build.gradle.LibraryExtension -import com.android.build.gradle.TestedExtension import com.android.build.gradle.api.BaseVariant -import com.apollographql.apollo3.compiler.capitalizeFirstLetter -import com.apollographql.apollo3.gradle.internal.ApolloGenerateSourcesTask import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.file.Directory -import org.gradle.api.provider.Provider -import org.gradle.api.tasks.TaskContainer -import org.gradle.api.tasks.TaskProvider -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile object AndroidProject { fun onEachVariant(project: Project, withTestVariants: Boolean = false, block: (BaseVariant) -> Unit) { - val androidExtension = project.androidExtensionOrFail - - val androidVariants = when (androidExtension) { - is LibraryExtension -> androidExtension.libraryVariants - is AppExtension -> androidExtension.applicationVariants - else -> { - // InstantAppExtension or something else we don't support yet - throw IllegalArgumentException("${androidExtension.javaClass.name} is not supported at the moment") - } + project.applicationVariants?.all { + block(it) } - - androidVariants.all { + project.libraryVariants?.all { block(it) } - if (withTestVariants && androidExtension is TestedExtension) { - androidExtension.testVariants.all { + if (withTestVariants) { + project.testVariants?.all { block(it) } - androidExtension.unitTestVariants.all { + project.unitTestVariants?.all { block(it) } } } - - fun registerGeneratedDirectory( - project: Project, - variant: BaseVariant, - wire: Service.OutputDirWire - ) { - val tasks = project.tasks - - // This doesn't seem to do much besides addJavaSourceFoldersToModel - // variant.registerJavaGeneratingTask(codegenProvider.get(), codegenProvider.get().outputDir.get().asFile) - - // This is apparently needed for intelliJ to find the generated files - // TODO: make this lazy (https://github.com/apollographql/apollo-android/issues/1454) - variant.addJavaSourceFoldersToModel(wire.outputDir.get().asFile) - // Tell the kotlin compiler to compile our files - tasks.named("compile${variant.name.capitalizeFirstLetter()}Kotlin").configure { - it.dependsOn(wire.task) - (it as KotlinCompile).source(wire.outputDir.get()) - } - } - - fun registerGeneratedDirectoryToAllVariants( - project: Project, - wire: Service.OutputDirWire, - ) { - onEachVariant(project) { variant -> - registerGeneratedDirectory(project, variant, wire) - } - } } diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/ApolloExtension.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/ApolloExtension.kt index 2309ff38d3a..f65155830b6 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/ApolloExtension.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/ApolloExtension.kt @@ -21,7 +21,7 @@ interface ApolloExtension : Service { * registers multiple services for an android project * * Android projects have variants for buildType/flavor combinations as well as test. Using this method will create a service for - * each variant and add the generated sources to the variant. + * each application/library variant and add the generated sources to the variant. * A variant typically contains several source sets as described in * https://developer.android.com/studio/build/build-variants?authuser=2#sourceset-build. This means you can put graphql files in * several folders: @@ -68,7 +68,7 @@ interface ApolloExtension : Service { * * If your project has more Kotlin source sets, services will be created for those as well */ - fun createAllKotlinJvmSourceSetServices(sourceFolder: String, nameSuffix: String, action: Action = Action {}) + fun createAllKotlinSourceSetServices(sourceFolder: String, nameSuffix: String, action: Action = Action {}) /** * For Kotlin native projects, whether to link Sqlite (-lsqlite3). This is required by `apollo-normalized-cache-sqlite` but diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinJvmProject.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinJvmProject.kt deleted file mode 100644 index 8701502fb1f..00000000000 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinJvmProject.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.apollographql.apollo3.gradle.api - -import com.android.build.gradle.api.BaseVariant -import com.apollographql.apollo3.gradle.api.Service -import com.apollographql.apollo3.gradle.api.kotlinJvmExtension -import com.apollographql.apollo3.gradle.api.kotlinMultiplatformExtension -import org.gradle.api.Project -import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.tasks.TaskProvider -import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet - -object KotlinJvmProject { - fun onEachSourceSet(project: Project, block: (KotlinSourceSet) -> Unit) { - project.kotlinJvmExtensionOrFail.sourceSets.forEach { - block(it) - } - } - - fun registerGeneratedDirectoryToMainSourceSet(project: Project, wire: Service.OutputDirWire) { - project.kotlinJvmExtensionOrFail.sourceSets.getByName("main").kotlin.srcDir(wire.outputDir) - } -} diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinMultiplatformProject.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinMultiplatformProject.kt deleted file mode 100644 index 63623245fce..00000000000 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/KotlinMultiplatformProject.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.apollographql.apollo3.gradle.api - -import com.apollographql.apollo3.gradle.internal.ApolloGenerateSourcesTask -import org.gradle.api.Project -import org.gradle.api.tasks.TaskProvider -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet - -object KotlinMultiplatformProject { - fun registerGeneratedDirectoryToCommonMainSourceSet(project: Project, wire: Service.OutputDirWire) { - val kotlinMultiplatformExtension = project.kotlinMultiplatformExtension - check(kotlinMultiplatformExtension != null) { - "ApolloGraphQL: no 'kotlin' extension found. Did you apply the Kotlin plugin?" - } - - val sourceDirectorySet = kotlinMultiplatformExtension.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME).kotlin - - // This should carry the task dependencies so nothing else should be required in theory - sourceDirectorySet.srcDir(wire.outputDir) - } -} diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt index 1764b392e2c..f57abf48de1 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt @@ -1,5 +1,6 @@ package com.apollographql.apollo3.gradle.api +import com.android.build.gradle.api.BaseVariant import com.apollographql.apollo3.compiler.OperationIdGenerator import com.apollographql.apollo3.compiler.OperationOutputGenerator import com.apollographql.apollo3.compiler.PackageNameGenerator @@ -10,7 +11,6 @@ import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty -import org.gradle.api.file.SourceDirectorySet import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property @@ -51,7 +51,7 @@ interface Service { /** * Adds the given directory as a GraphQL source root * - * Use [srcDir] if your files are outside of "src/main/graphql" or to have them in multiple folders. + * Use [srcDir] if your files are outside "src/main/graphql" or to have them in multiple folders. * */ fun srcDir(directory: Any) @@ -95,7 +95,7 @@ interface Service { /** * By default, Apollo uses `Sha256` hashing algorithm to generate an ID for the query. * To provide a custom ID generation logic, pass an `instance` that implements the [OperationIdGenerator]. How the ID is generated is - * indifferent to the compiler. It can be an hashing algorithm or generated by a backend. + * indifferent to the compiler. It can be a hashing algorithm or generated by a backend. * * Example Md5 hash generator: * ```groovy @@ -214,7 +214,7 @@ interface Service { val generateApolloMetadata: Property /** - * A list of [Regex] patterns for input/scalar/enum types that should be generated whether or not they are used by queries/fragments + * A list of [Regex] patterns for input/scalar/enum types that should be generated whether they are used by queries/fragments * in this module. When using multiple modules, Apollo Android will generate all the types by default in the root module * because the root module doesn't know what types are going to be used by dependent modules. This can be prohibitive in terms * of compilation speed for large projects. If that's the case, opt-in the types that are used by multiple dependent modules here. @@ -231,7 +231,7 @@ interface Service { * Default value is `false`, means only interfaces are been generated. * * Most of the time, fragment implementations are not needed because you can easily access fragments interfaces and read all - * data from your queries. They are needed if you want to be able to build fragments outside of an operation. For an exemple + * data from your queries. They are needed if you want to be able to build fragments outside an operation. For an exemple * to programmatically build a fragment that is reused in another part of your code or to read and write fragments to the cache. */ val generateFragmentImplementations: Property @@ -257,7 +257,7 @@ interface Service { /** * The directory where the generated models will be written. It's called [outputDir] but this an "input" parameter for the compiler - * If you want a [DirectoryProperty] that carries the task dependency, use [withOutputDir] + * If you want a [DirectoryProperty] that carries the task dependency, use [outputDirConnection] */ val outputDir: DirectoryProperty @@ -270,7 +270,7 @@ interface Service { /** * The file where the operation output will be written. It's called [operationOutputFile] but this an "input" parameter for the compiler - * If you want a [RegularFileProperty] that carries the task dependency, use [withOperationOutput] + * If you want a [RegularFileProperty] that carries the task dependency, use [operationOutputConnection] */ val operationOutputFile: RegularFileProperty @@ -290,12 +290,15 @@ interface Service { fun registry(configure: Action) /** - * overrides the way operationOutput is wired. Use this if you want to wire the generated operationOutput. By default, oeprationOutput - * is not generated and therefore not wired. + * overrides the way operationOutput is connected. + * Use this if you want to connect the generated operationOutput. For an example + * you can use this to send the modified queries to your backend for whitelisting + * + * By default, operationOutput is not connected */ - fun withOperationOutput(action: Action) + fun operationOutputConnection(action: Action) - class OperationOutputWire( + class OperationOutputConnection( /** * The task that produces operationOutput */ @@ -311,23 +314,76 @@ interface Service { ) /** - * overrides the way the task is wired. Use this if you want to wire the generated sources to another task than the default destination. + * overrides the way the task is connected. + * Use this if you want to connect the generated sources to another task than the default destination. * - * By default, the generated sources are wired to: + * By default, the generated sources are connected to: * - main sourceSet for Kotlin projects * - commonMain sourceSet for Kotlin multiplatform projects - * - all variants for Android projects + * - all application variants for Android projects */ - fun withOutputDir(action: Action) + fun outputDirConnection(action: Action) - class OutputDirWire( - /** - * The task that produces outputDir - */ - val task: TaskProvider, - /** - * The directory where the generated models will be written - */ - val outputDir: Provider, - ) + /** + * An [OutputDirConnection] defines how the generated sources are connected to the rest of the + * build. + * + * It provides helpers for the most common options as well as direct access to an output [Provider] + * that will carry task dependency. + */ + interface OutputDirConnection { + /** + * Connects the generated sources to the given Kotlin source set. + * Throws if the Kotlin plugin is not applied + * + * @param name: the name of the source set. For an example, "commonTest" + */ + fun connectToKotlinSourceSet(name: String) + + /** + * Connects the generated sources to the given Java source set. + * Throws if the Java plugin is not applied + * + * @param name: the name of the source set. For an example, "test" + */ + fun connectToJavaSourceSet(name: String) + + /** + * Connects the generated sources to all the Android application variants. + * Throws if the Android Application plugin is not applied + */ + fun connectToAllAndroidApplicationVariants() + + /** + * Connects the generated sources to all the Android application variants. + * Throws if the Android Library plugin is not applied + */ + fun connectToAllAndroidLibraryVariants() + + /** + * Connects the generated sources to all the Android test variants. + * Throws if the Android plugin is not applied + */ + fun connectToAllAndroidTestVariants() + + /** + * Connects the generated sources to all the Android test variants. + * Throws if the Android plugin is not applied + */ + fun connectToAllAndroidUnitTestVariants() + + fun connectToAndroidVariant(variant: BaseVariant) + + /** + * The directory where the generated models will be written. + * This provider carries task dependency information. + */ + val outputDir: Provider + + /** + * The task that produces outputDir. Usually this is not needed as [outputDir] carries + * task dependency. + */ + val task: TaskProvider + } } diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/project.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/project.kt index 062336e630a..105e3d45f20 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/project.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/project.kt @@ -1,14 +1,24 @@ package com.apollographql.apollo3.gradle.api +import com.android.build.gradle.AppExtension import com.android.build.gradle.BaseExtension +import com.android.build.gradle.LibraryExtension +import com.android.build.gradle.TestedExtension +import com.android.build.gradle.api.ApplicationVariant +import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.api.LibraryVariant +import com.android.build.gradle.api.TestVariant +import com.android.build.gradle.api.UnitTestVariant +import org.gradle.api.DomainObjectSet import org.gradle.api.Project +import org.gradle.api.internal.DefaultDomainObjectSet import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension val Project.kotlinMultiplatformExtension get() = extensions.findByName("kotlin") as? KotlinMultiplatformExtension -val Project.kotlinJvmExtension +val Project.kotlinProjectExtension get() = extensions.findByName("kotlin") as? KotlinProjectExtension val Project.androidExtension @@ -17,10 +27,34 @@ val Project.androidExtension val Project.kotlinMultiplatformExtensionOrFail get() = kotlinMultiplatformExtension ?: throw IllegalStateException("ApolloGraphQL: no 'kotlin' extension found. Did you apply the Kotlin multiplatform plugin?") -val Project.kotlinJvmExtensionOrFail - get() = kotlinJvmExtension ?: throw IllegalStateException("ApolloGraphQL: no 'kotlin' extension found. Did you apply the Kotlin jvm plugin?") +val Project.kotlinProjectExtensionOrThrow + get() = kotlinProjectExtension ?: throw IllegalStateException("ApolloGraphQL: no 'kotlin' extension found. Did you apply the Kotlin jvm plugin?") -val Project.androidExtensionOrFail +val Project.androidExtensionOrThrow get() = androidExtension ?: throw IllegalStateException("ApolloGraphQL: no 'android' extension found. Did you apply the Android plugin?") val Project.isKotlinMultiplatform get() = pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform") + +val Project.libraryVariants: DomainObjectSet? + get() { + return (androidExtensionOrThrow as? LibraryExtension) + ?.libraryVariants + } + +val Project.applicationVariants: DomainObjectSet? + get() { + return (androidExtensionOrThrow as? AppExtension) + ?.applicationVariants + } + +val Project.unitTestVariants: DomainObjectSet? + get() { + return (androidExtensionOrThrow as? TestedExtension) + ?.unitTestVariants + } + +val Project.testVariants: DomainObjectSet? + get() { + return (androidExtensionOrThrow as? TestedExtension) + ?.testVariants + } diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt index 6c6f881fdca..4a49bc4d856 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt @@ -7,13 +7,12 @@ import com.apollographql.apollo3.compiler.capitalizeFirstLetter import com.apollographql.apollo3.gradle.api.AndroidProject import com.apollographql.apollo3.gradle.api.ApolloAttributes import com.apollographql.apollo3.gradle.api.ApolloExtension -import com.apollographql.apollo3.gradle.api.KotlinJvmProject -import com.apollographql.apollo3.gradle.api.KotlinMultiplatformProject import com.apollographql.apollo3.gradle.api.Service import com.apollographql.apollo3.gradle.api.androidExtension import com.apollographql.apollo3.gradle.api.isKotlinMultiplatform -import com.apollographql.apollo3.gradle.api.kotlinJvmExtension +import com.apollographql.apollo3.gradle.api.kotlinProjectExtension import com.apollographql.apollo3.gradle.api.kotlinMultiplatformExtension +import com.apollographql.apollo3.gradle.api.kotlinProjectExtensionOrThrow import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -26,6 +25,7 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.TaskProvider import org.gradle.util.GradleVersion import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import java.io.File @@ -258,14 +258,15 @@ abstract class DefaultApolloExtension( } if (service.operationOutputAction != null) { - val operationOutputWire = Service.OperationOutputWire( + val operationOutputConnection = Service.OperationOutputConnection( task = codegenProvider, operationOutputFile = codegenProvider.flatMap { it.operationOutputFile } ) - service.operationOutputAction!!.execute(operationOutputWire) + service.operationOutputAction!!.execute(operationOutputConnection) } - val outputDirWire = Service.OutputDirWire( + val outputDirWire = DefaultOutputDirConnection( + project = project, task = codegenProvider, outputDir = codegenProvider.flatMap { it.outputDir } ) @@ -296,11 +297,22 @@ abstract class DefaultApolloExtension( /** * The default wiring. */ - private val mainWireAction = Action { wire -> + private val mainWireAction = Action { wire -> when { - project.kotlinMultiplatformExtension != null -> KotlinMultiplatformProject.registerGeneratedDirectoryToCommonMainSourceSet(project, wire) - project.androidExtension != null -> AndroidProject.registerGeneratedDirectoryToAllVariants(project, wire) - project.kotlinJvmExtension != null -> KotlinJvmProject.registerGeneratedDirectoryToMainSourceSet(project, wire) + project.kotlinMultiplatformExtension != null -> { + wire.connectToKotlinSourceSet(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) + } + project.androidExtension != null -> { + /** + * Call both application and library + * Only one will be active at a time + */ + wire.connectToAllAndroidApplicationVariants() + wire.connectToAllAndroidLibraryVariants() + } + project.kotlinProjectExtension != null -> { + wire.connectToKotlinSourceSet("main") + } else -> throw IllegalStateException("Cannot find the Kotlin extension, please apply a kotlin plugin") } } @@ -449,7 +461,11 @@ abstract class DefaultApolloExtension( } } - override fun createAllAndroidVariantServices(sourceFolder: String, nameSuffix: String, action: Action) { + override fun createAllAndroidVariantServices( + sourceFolder: String, + nameSuffix: String, + action: Action + ) { /** * The android plugin will call us back when the variants are ready but before that happens, disable the default service */ @@ -475,18 +491,18 @@ abstract class DefaultApolloExtension( } } if (service.outputDirAction == null) { - service.outputDirAction = Action { wire -> - AndroidProject.registerGeneratedDirectory(project, variant, wire) + service.outputDirAction = Action { wire -> + wire.connectToAndroidVariant(variant) } } registerService(service) } } - override fun createAllKotlinJvmSourceSetServices(sourceFolder: String, nameSuffix: String, action: Action) { + override fun createAllKotlinSourceSetServices(sourceFolder: String, nameSuffix: String, action: Action) { registerDefaultService = false - KotlinJvmProject.onEachSourceSet(project) { kotlinSourceSet -> + project.kotlinProjectExtensionOrThrow.sourceSets.forEach { kotlinSourceSet -> val name = "${kotlinSourceSet.name}${nameSuffix.capitalizeFirstLetter()}" val service = project.objects.newInstance(DefaultService::class.java, project, name) @@ -505,7 +521,7 @@ abstract class DefaultApolloExtension( service.srcDir("src/${kotlinSourceSet.name}/graphql/$sourceFolder") } if (service.outputDirAction == null) { - service.outputDirAction = Action { wire -> + service.outputDirAction = Action { wire -> kotlinSourceSet.kotlin.srcDir(wire.outputDir) } } diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt new file mode 100644 index 00000000000..0fe3c7b7c61 --- /dev/null +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt @@ -0,0 +1,75 @@ +package com.apollographql.apollo3.gradle.internal + +import com.android.build.gradle.api.BaseVariant +import com.apollographql.apollo3.compiler.capitalizeFirstLetter +import com.apollographql.apollo3.gradle.api.Service +import com.apollographql.apollo3.gradle.api.applicationVariants +import com.apollographql.apollo3.gradle.api.kotlinProjectExtensionOrThrow +import com.apollographql.apollo3.gradle.api.libraryVariants +import com.apollographql.apollo3.gradle.api.testVariants +import com.apollographql.apollo3.gradle.api.unitTestVariants +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.TaskProvider +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +internal class DefaultOutputDirConnection( + private val project: Project, + override val task: TaskProvider, + override val outputDir: Provider +): Service.OutputDirConnection { + override fun connectToKotlinSourceSet(name: String) { + project.kotlinProjectExtensionOrThrow.sourceSets.getByName(name).kotlin.srcDir(outputDir) + } + + override fun connectToJavaSourceSet(name: String) { + project.convention.getByType(JavaPluginConvention::class.java) + .sourceSets + .getByName(name) + .allJava + .srcDir(outputDir) + } + + override fun connectToAndroidVariant(variant: BaseVariant) { + val tasks = project.tasks + + // This doesn't seem to do much besides addJavaSourceFoldersToModel + // variant.registerJavaGeneratingTask(codegenProvider.get(), codegenProvider.get().outputDir.get().asFile) + + // This is apparently needed for intelliJ to find the generated files + // TODO: make this lazy (https://github.com/apollographql/apollo-android/issues/1454) + variant.addJavaSourceFoldersToModel(outputDir.get().asFile) + // Tell the kotlin compiler to compile our files + tasks.named("compile${variant.name.capitalizeFirstLetter()}Kotlin").configure { + it.dependsOn(task) + (it as KotlinCompile).source(outputDir.get()) + } + } + + override fun connectToAllAndroidApplicationVariants() { + project.applicationVariants?.all { variant -> + connectToAndroidVariant(variant) + } + } + + override fun connectToAllAndroidLibraryVariants() { + project.libraryVariants?.all { variant -> + connectToAndroidVariant(variant) + } + } + + override fun connectToAllAndroidTestVariants() { + project.testVariants?.all { variant -> + connectToAndroidVariant(variant) + } + } + + override fun connectToAllAndroidUnitTestVariants() { + project.unitTestVariants?.all { variant -> + connectToAndroidVariant(variant) + } + } +} \ No newline at end of file diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt index 1272b5246c0..76517d71e5a 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt @@ -11,13 +11,10 @@ import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty -import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider import org.gradle.api.provider.SetProperty import org.gradle.util.GradleVersion import javax.inject.Inject @@ -131,16 +128,15 @@ abstract class DefaultService @Inject constructor(val project: Project, override this.registry = registry } - var operationOutputAction: Action? = null + var operationOutputAction: Action? = null - override fun withOperationOutput(action: Action) { + override fun operationOutputConnection(action: Action) { this.operationOutputAction = action - generateOperationOutput.set(true) } - var outputDirAction: Action? = null + var outputDirAction: Action? = null - override fun withOutputDir(action: Action) { + override fun outputDirConnection(action: Action) { this.outputDirAction = action } diff --git a/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/ServiceTests.kt b/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/ServiceTests.kt index fa09cf5616a..6a7c68ee9aa 100644 --- a/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/ServiceTests.kt +++ b/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/ServiceTests.kt @@ -243,8 +243,7 @@ class ServiceTests { fun `operationOutput generates queries with __typename`() { withSimpleProject(""" apollo { - withOperationOutput { - } + generateOperationOutput.set(true) } """.trimIndent()) { dir -> val result = TestUtils.executeTask("generateApolloSources", dir) @@ -264,8 +263,7 @@ class ServiceTests { withSimpleProject(""" apollo { filePathAwarePackageNameGenerator() - withOperationOutput { - } + generateOperationOutput.set(true) } """.trimIndent()) { dir -> val result = TestUtils.executeTask("generateApolloSources", dir) @@ -284,7 +282,8 @@ class ServiceTests { fun `operationOutputFile carries task dependencies`() { withSimpleProject(""" apollo { - withOperationOutput { + generateOperationOutput.set(true) + operationOutputConnection { tasks.register("customTaskService") { inputs.file(operationOutputFile) } @@ -333,7 +332,7 @@ class ServiceTests { } @Test - fun `withOutputDir can rewire to the test source set`() { + fun `outputDirConnection can connect to the test source set`() { withTestProject("testSourceSet") { dir -> TestUtils.executeTask("build", dir) diff --git a/apollo-gradle-plugin/testProjects/kotlinJvmSourceSets/build.gradle.kts b/apollo-gradle-plugin/testProjects/kotlinJvmSourceSets/build.gradle.kts index 58958f11ea8..edd4639ad52 100644 --- a/apollo-gradle-plugin/testProjects/kotlinJvmSourceSets/build.gradle.kts +++ b/apollo-gradle-plugin/testProjects/kotlinJvmSourceSets/build.gradle.kts @@ -33,7 +33,7 @@ dependencies { } configure { - createAllKotlinJvmSourceSetServices(".", "example") { + createAllKotlinSourceSetServices(".", "example") { filePathAwarePackageNameGenerator() schemaFile.set(file("src/main/graphql/com/example/schema.sdl")) } diff --git a/apollo-gradle-plugin/testProjects/testSourceSet/build.gradle.kts b/apollo-gradle-plugin/testProjects/testSourceSet/build.gradle.kts index f227c9af1e4..d378a4b34ca 100644 --- a/apollo-gradle-plugin/testProjects/testSourceSet/build.gradle.kts +++ b/apollo-gradle-plugin/testProjects/testSourceSet/build.gradle.kts @@ -39,8 +39,7 @@ tasks.withType { } configure { - withOutputDir { - val kotlinProjectExtension = project.extensions.get("kotlin") as KotlinProjectExtension - kotlinProjectExtension.sourceSets.getByName("test").kotlin.srcDir(outputDir) + outputDirConnection { + connectToKotlinSourceSet("test") } } \ No newline at end of file diff --git a/docs/source/essentials/60-plugin-configuration.mdx b/docs/source/essentials/60-plugin-configuration.mdx index 15f79f42fb6..2ab6994d848 100644 --- a/docs/source/essentials/60-plugin-configuration.mdx +++ b/docs/source/essentials/60-plugin-configuration.mdx @@ -57,14 +57,12 @@ By default, Apollo Android adds generated source: * to `commonMain` for multiplatform projects * to all non-test variants for Android projects -You can customize this behavior with the `withOutputDir` property. For exemple, to wire a service to all the test source set of a Kotlin JVM project: +You can customize this behavior with the `outputDirConnection` property. For exemple, to wire a service to the test source set of a Kotlin JVM project: ```kotlin apollo { - withOutputDir { - val kotlinProjectExtension = project.extensions.get("kotlin") as KotlinProjectExtension - // Because outputDir is a Gradle Property, it will carry the task dependency to the codegen task - kotlinProjectExtension.sourceSets.getByName("test").kotlin.srcDir(outputDir) + outputDirConnection { + connectToKotlinSourceSet("test") } } ``` diff --git a/tests/integration-tests/build.gradle.kts b/tests/integration-tests/build.gradle.kts index 6c8ffa670f1..ed274f74912 100644 --- a/tests/integration-tests/build.gradle.kts +++ b/tests/integration-tests/build.gradle.kts @@ -38,7 +38,7 @@ configure { service(it.name) { when (it.name) { "httpcache" -> { - withOperationOutput {} + generateOperationOutput.set(true) customScalarsMapping.set(mapOf( "Date" to "kotlinx.datetime.LocalDate" )) @@ -61,15 +61,8 @@ configure { codegenModels.set("operationBased") flattenModels.set(false) - withOutputDir { - val kotlinMultiplatformExtension = project.kotlinMultiplatformExtension!! - - val sourceDirectorySet = kotlinMultiplatformExtension - .sourceSets - .getByName(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) - .kotlin - - sourceDirectorySet.srcDir(outputDir) + outputDirConnection { + connectToKotlinSourceSet("commonTest") } } } From 4dcbb5daf6f9a23ce55114247752f734b707b177 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Tue, 27 Jul 2021 12:41:34 +0200 Subject: [PATCH 2/2] added a test to wire a service to unit tests --- .../apollo3/gradle/api/Service.kt | 6 +- .../internal/ApolloGenerateSourcesTask.kt | 2 + .../gradle/internal/DefaultApolloExtension.kt | 64 +++++++-------- .../internal/DefaultOutputDirConnection.kt | 2 +- .../gradle/test/AndroidProjectTests.kt | 8 ++ .../androidTestVariants/build.gradle.kts | 77 +++++++++++++++++++ .../androidTestVariants/settings.gradle.kts | 0 .../src/main/AndroidManifest.xml | 3 + .../graphql/com/example/operations.graphql | 3 + .../src/test/graphql/com/example/schema.sdl | 9 +++ .../src/test/java/com/example/Test.kt | 5 ++ .../androidVariants/build.gradle.kts | 1 + 12 files changed, 140 insertions(+), 40 deletions(-) create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/build.gradle.kts create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/settings.gradle.kts create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/src/main/AndroidManifest.xml create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/operations.graphql create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/schema.sdl create mode 100644 apollo-gradle-plugin/testProjects/androidTestVariants/src/test/java/com/example/Test.kt diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt index f57abf48de1..16c2f947bd0 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt @@ -361,13 +361,13 @@ interface Service { fun connectToAllAndroidLibraryVariants() /** - * Connects the generated sources to all the Android test variants. + * Connects the generated sources to all the Android instrumented test variants. * Throws if the Android plugin is not applied */ - fun connectToAllAndroidTestVariants() + fun connectToAllAndroidInstrumentedTestVariants() /** - * Connects the generated sources to all the Android test variants. + * Connects the generated sources to all the Android unit test variants. * Throws if the Android plugin is not applied */ fun connectToAllAndroidUnitTestVariants() diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt index 540a68c9c9c..126ab2f89bb 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt @@ -21,6 +21,7 @@ import com.apollographql.apollo3.compiler.PackageNameGenerator import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty @@ -36,6 +37,7 @@ import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.TaskAction import javax.inject.Inject diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt index 4a49bc4d856..044d5996ec0 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt @@ -1,5 +1,6 @@ package com.apollographql.apollo3.gradle.internal +import com.android.build.gradle.api.BaseVariant import com.apollographql.apollo3.compiler.OperationIdGenerator import com.apollographql.apollo3.compiler.OperationOutputGenerator import com.apollographql.apollo3.compiler.PackageNameGenerator @@ -13,6 +14,7 @@ import com.apollographql.apollo3.gradle.api.isKotlinMultiplatform import com.apollographql.apollo3.gradle.api.kotlinProjectExtension import com.apollographql.apollo3.gradle.api.kotlinMultiplatformExtension import com.apollographql.apollo3.gradle.api.kotlinProjectExtensionOrThrow +import com.apollographql.apollo3.gradle.internal.DefaultApolloExtension.Companion.isReallyEmpty import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task @@ -464,73 +466,63 @@ abstract class DefaultApolloExtension( override fun createAllAndroidVariantServices( sourceFolder: String, nameSuffix: String, - action: Action + action: Action, ) { /** - * The android plugin will call us back when the variants are ready but before that happens, disable the default service + * The android plugin will call us back when the variants are ready but before `afterEvaluate`, + * disable the default service */ registerDefaultService = false - AndroidProject.onEachVariant(project = project, withTestVariants = true) { variant -> + check(!File(sourceFolder).isRooted && !sourceFolder.startsWith("../..")) { + """ + ApolloGraphQL: using 'sourceFolder = "$sourceFolder"' makes no sense with Android variants as the same generated models will be used in all variants. + """.trimIndent() + } + + AndroidProject.onEachVariant(project, true) { variant -> val name = "${variant.name}${nameSuffix.capitalizeFirstLetter()}" - val service = project.objects.newInstance(DefaultService::class.java, project, name) - action.execute(service) + service(name) { service -> + action.execute(service) - check(!service.sourceFolder.isPresent) { - "ApolloGraphQL: service.sourceFolder is not used when calling createAllAndroidVariantServices. Use the parameter instead" - } - if (service.graphqlSourceDirectorySet.isReallyEmpty) { - check(!File(sourceFolder).isRooted && !sourceFolder.startsWith("../..")) { - """ - ApolloGraphQL: using 'sourceFolder = "$sourceFolder"' makes no sense with Android variants as the same generated models will be used in all variants. - """.trimIndent() + check(!service.sourceFolder.isPresent) { + "ApolloGraphQL: service.sourceFolder is not used when calling createAllAndroidVariantServices. Use the parameter instead" } variant.sourceSets.forEach { sourceProvider -> service.srcDir("src/${sourceProvider.name}/graphql/$sourceFolder") } - } - if (service.outputDirAction == null) { - service.outputDirAction = Action { wire -> + (service as DefaultService).outputDirAction = Action { wire -> wire.connectToAndroidVariant(variant) } } - registerService(service) } } override fun createAllKotlinSourceSetServices(sourceFolder: String, nameSuffix: String, action: Action) { registerDefaultService = false + check(!File(sourceFolder).isRooted && !sourceFolder.startsWith("../..")) { + """ApolloGraphQL: using 'sourceFolder = "$sourceFolder"' makes no sense with Kotlin source sets as the same generated models will be used in all source sets. + """.trimMargin() + } + project.kotlinProjectExtensionOrThrow.sourceSets.forEach { kotlinSourceSet -> val name = "${kotlinSourceSet.name}${nameSuffix.capitalizeFirstLetter()}" - val service = project.objects.newInstance(DefaultService::class.java, project, name) - action.execute(service) - - check(!service.sourceFolder.isPresent) { - "ApolloGraphQL: service.sourceFolder is not used when calling createAllKotlinJvmSourceSetServices. Use the parameter instead" - } - - if (service.graphqlSourceDirectorySet.isReallyEmpty) { - check(!File(sourceFolder).isRooted && !sourceFolder.startsWith("../..")) { - """ApolloGraphQL: using 'sourceFolder = "$sourceFolder"' makes no sense with Kotlin source sets as the same generated models will be used in all source sets. - """.trimMargin() + service(name) { service -> + action.execute(service) + check(!service.sourceFolder.isPresent) { + "ApolloGraphQL: service.sourceFolder is not used when calling createAllKotlinJvmSourceSetServices. Use the parameter instead" } - service.srcDir("src/${kotlinSourceSet.name}/graphql/$sourceFolder") - } - if (service.outputDirAction == null) { - service.outputDirAction = Action { wire -> - kotlinSourceSet.kotlin.srcDir(wire.outputDir) + (service as DefaultService).outputDirAction = Action { connection -> + kotlinSourceSet.kotlin.srcDir(connection.outputDir) } } - - registerService(service) } } - abstract override val linkSqlite: Property companion object { diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt index 0fe3c7b7c61..36ea20b929b 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultOutputDirConnection.kt @@ -61,7 +61,7 @@ internal class DefaultOutputDirConnection( } } - override fun connectToAllAndroidTestVariants() { + override fun connectToAllAndroidInstrumentedTestVariants() { project.testVariants?.all { variant -> connectToAndroidVariant(variant) } diff --git a/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/AndroidProjectTests.kt b/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/AndroidProjectTests.kt index e31c70493b7..ed24fffa00a 100644 --- a/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/AndroidProjectTests.kt +++ b/apollo-gradle-plugin/src/test/kotlin/com/apollographql/apollo3/gradle/test/AndroidProjectTests.kt @@ -67,4 +67,12 @@ class AndroidProjectTests { executeTaskAndAssertSuccess(":compileFullDebugAndroidTestKotlin", dir) } } + + @Test + fun `can connect outputDir to tests`() { + withTestProject("androidTestVariants") {dir -> + // compile library variants + executeTaskAndAssertSuccess(":build", dir) + } + } } diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/build.gradle.kts b/apollo-gradle-plugin/testProjects/androidTestVariants/build.gradle.kts new file mode 100644 index 00000000000..566f7700d97 --- /dev/null +++ b/apollo-gradle-plugin/testProjects/androidTestVariants/build.gradle.kts @@ -0,0 +1,77 @@ +import com.apollographql.apollo3.gradle.api.ApolloExtension +import com.android.build.gradle.BaseExtension + +buildscript { + apply(from = "../../../gradle/dependencies.gradle") + + repositories { + maven { + url = uri("../../../build/localMaven") + } + google() + mavenCentral() + } + dependencies { + classpath(groovy.util.Eval.x(project, "x.dep.android.plugin")) + classpath(groovy.util.Eval.x(project, "x.dep.apollo.plugin")) + classpath(groovy.util.Eval.x(project, "x.dep.kotlin.plugin")) + } +} + + +apply(plugin = "com.android.library") +apply(plugin = "org.jetbrains.kotlin.android") +apply(plugin = "com.apollographql.apollo3") + +repositories { + maven { + url = uri("../../../build/localMaven") + } + google() + mavenCentral() +} + +dependencies { + add("implementation", groovy.util.Eval.x(project, "x.dep.apollo.api")) +} + +configure { + compileSdkVersion(groovy.util.Eval.x(project, "x.androidConfig.compileSdkVersion").toString().toInt()) + + defaultConfig { + minSdkVersion(groovy.util.Eval.x(project, "x.androidConfig.minSdkVersion").toString()) + targetSdkVersion(groovy.util.Eval.x(project, "x.androidConfig.targetSdkVersion").toString()) + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + // This doesn't really make sense for a library project, but still allows to compile flavor source sets + flavorDimensions("version") + productFlavors { + create("demo") { + versionNameSuffix = "-demo" + } + create("full") { + versionNameSuffix = "-full" + } + } +} + +configure { + service("test") { + srcDir("src/test/graphql") + packageName.set("com.example") + outputDirConnection { + connectToAllAndroidUnitTestVariants() + } + } +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} \ No newline at end of file diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/settings.gradle.kts b/apollo-gradle-plugin/testProjects/androidTestVariants/settings.gradle.kts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/src/main/AndroidManifest.xml b/apollo-gradle-plugin/testProjects/androidTestVariants/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..4fc6746a971 --- /dev/null +++ b/apollo-gradle-plugin/testProjects/androidTestVariants/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/operations.graphql b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/operations.graphql new file mode 100644 index 00000000000..05cc8063336 --- /dev/null +++ b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/operations.graphql @@ -0,0 +1,3 @@ +query Test { + testField +} \ No newline at end of file diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/schema.sdl b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/schema.sdl new file mode 100644 index 00000000000..6ba540a4122 --- /dev/null +++ b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/graphql/com/example/schema.sdl @@ -0,0 +1,9 @@ +type Query { + debugField: String! + releaseField: String! + mainField: String! + demoField: String! + fullField: String! + testField: String! + androidTestField: String! +} \ No newline at end of file diff --git a/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/java/com/example/Test.kt b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/java/com/example/Test.kt new file mode 100644 index 00000000000..52baa914904 --- /dev/null +++ b/apollo-gradle-plugin/testProjects/androidTestVariants/src/test/java/com/example/Test.kt @@ -0,0 +1,5 @@ +package com.example + +fun main() { + println(com.example.TestQuery::class.java.name) +} \ No newline at end of file diff --git a/apollo-gradle-plugin/testProjects/androidVariants/build.gradle.kts b/apollo-gradle-plugin/testProjects/androidVariants/build.gradle.kts index b64691335df..ddc7ae42437 100644 --- a/apollo-gradle-plugin/testProjects/androidVariants/build.gradle.kts +++ b/apollo-gradle-plugin/testProjects/androidVariants/build.gradle.kts @@ -62,6 +62,7 @@ configure { configure { createAllAndroidVariantServices(".", "example") { + // Here we set the same schema file for all variants schemaFile.set(file("src/main/graphql/com/example/schema.sdl")) packageName.set("com.example") }