Skip to content

Commit 8a273b5

Browse files
authored
[🐘gradle-plugin] Remix the multi-module configurations once again (#6027)
* fix hedvig use case * Clean up the multi-module configurations * spelling
1 parent fa60782 commit 8a273b5

File tree

8 files changed

+169
-169
lines changed

8 files changed

+169
-169
lines changed

docs/source/migration/4.0.mdx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ val call = client.query(MyQuery())
234234

235235
In Apollo Kotlin 3, you could depend on an upstream GraphQL module by using the `apolloMetadata` configuration.
236236

237-
In Apollo Kotlin 4, this is now done with the `Service.dependsOn()`. This allows better management of dependencies when multiple services are used as better symmetry with `isADependencyOf` below.
237+
In Apollo Kotlin 4, this is now done with the `Service.dependsOn()`. `Service.dependsOn()` works for multi-services repositories and, by hiding the configuration names, allows us to change the implementation in the future if needed. For an example to accommodate [Gradle project isolation](https://docs.gradle.org/current/userguide/isolated_projects.html).
238238

239239
```kotlin
240240
// feature1/build.gradle.kts
@@ -272,7 +272,7 @@ apollo {
272272

273273
In multi-module projects, by default, all the types of an upstream module are generated because there is no way to know in advance what types are going to be used by downstream modules. For large projects this can lead to a lot of unused code and an increased build time.
274274

275-
To avoid this, in Apollo Kotlin 3 you could manually specify which types to generate by using `alwaysGenerateTypesMatching`. In Apollo Kotlin 4 this can now be computed automatically by detecting which types are used by the downstream modules.
275+
To avoid this, in Apollo Kotlin 3 you could manually specify which types to generate by using `alwaysGenerateTypesMatching`. In Apollo Kotlin 4 you can opt in auto-detection of used types.
276276

277277
To enable this, add the "opposite" link of dependencies with `isADependencyOf()`.
278278

@@ -319,9 +319,27 @@ dependencies {
319319
apolloUsedCoordinates(project(":feature1"))
320320
}
321321
```
322-
### Publishing is no longer configured automatically
322+
### All schema types are generated in the schema module
323323

324-
Apollo artifacts are not automatically published anymore. To publish them, create a `MavenPublication`:
324+
Apollo Kotlin 3 allows to generate schema types for enums or input types in any module. While very flexible, this creates a lot of complexity:
325+
326+
- Duplicate types could be generated in sibling modules.
327+
- It's unclear what package name to use.
328+
- Using the downstream module package name means the qualified name of the class changes if the type is moved to another module.
329+
- Using the schema module package name can be surprising as it's not the one specified in the Gradle configuration.
330+
- Gradle has APIs to aggregate all projects in a project isolation compatible way (see [gradle#22514](https://github.com/gradle/gradle/issues/22514)). But it's not clear yet how to do this for a subset of the projects (see [gradle#29037](https://github.com/gradle/gradle/issues/29037)).
331+
332+
In Apollo Kotlin 4, we decided to enforce generating all schema types in a single module, the schema module. This restriction simplifies the Gradle plugin and makes it easier to debug and evolve that code.
333+
334+
It also means that you can't publish your schema module with a subset of the types and let other modules generate their own in another repository. If you are publishing your schema module, it needs to contain all the schema types used by your consumers, either using `alwaysGenerateTypesMatching.set(listOf(".*"))` or manually adding them.
335+
336+
If that is too much of a limitation, please open an issue and we will revisit.
337+
338+
### Apollo metadata publications are no longer created automatically
339+
340+
Apollo Kotlin 3 automatically creates an "apollo" publication using artifactId `${project.name}-apollo`. This created dependency resolution issues in some projects (see [apollo-kotlin#4350](https://github.com/apollographql/apollo-kotlin/issues/4350)).
341+
342+
Apollo Kotlin 4 exposes a software component instead of a publication to give more control over how publications are created. In order to publish the Apollo metadata, create a `MavenPublication` manually:
325343

326344
```kotlin
327345
publishing {

libraries/apollo-gradle-plugin-external/api/apollo-gradle-plugin-external.api

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
public final class com/apollographql/apollo/gradle/api/ApolloAttributes {
2-
public static final field INSTANCE Lcom/apollographql/apollo/gradle/api/ApolloAttributes;
3-
public final fun getAPOLLO_SERVICE_ATTRIBUTE ()Lorg/gradle/api/attributes/Attribute;
4-
}
5-
6-
public abstract interface class com/apollographql/apollo/gradle/api/ApolloAttributes$Service : org/gradle/api/Named {
7-
}
8-
91
public final class com/apollographql/apollo/gradle/api/ApolloDependencies {
102
public fun <init> (Lorg/gradle/api/artifacts/dsl/DependencyHandler;)V
113
public final fun getApi ()Lorg/gradle/api/artifacts/Dependency;

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/api/ApolloAttributes.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/api/Service.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,13 @@ interface Service {
786786
fun isADependencyOf(dependencyNotation: Any)
787787

788788
/**
789-
* Same as [dependsOn] but tries to do automatic cross-project configuration.
790-
* This is highly experimental and probably not compatible with most Gradle best practices.
789+
* Same as [dependsOn] but allows for automatic detection of used types.
790+
* This works by adding the current project to the upstream project dependencies using cross-project configuration.
791791
*
792-
* Use at your own risks!
792+
* This function is experimental and not compatible with [Gradle project isolation](https://docs.gradle.org/current/userguide/isolated_projects.html).
793793
*
794794
* @param bidirectional if true and if [dependencyNotation] is a project dependency,
795-
* this version of [dependsOn] also calls [isADependencyOf] automatically by using
796-
* cross-project configuration. This is experimental and probably not project isolation compatible.
797-
*
795+
* automatically configure the symmetrical dependency for automatic detection of used types.
798796
*/
799797
@ApolloExperimental
800798
fun dependsOn(dependencyNotation: Any, bidirectional: Boolean)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.apollographql.apollo.gradle.internal
2+
3+
import org.gradle.api.attributes.Attribute
4+
5+
internal val APOLLO_SERVICE_ATTRIBUTE = Attribute.of("com.apollographql.service", String::class.java)
6+
internal val APOLLO_DIRECTION_ATTRIBUTE = Attribute.of("com.apollographql.direction", String::class.java)
7+
8+
internal enum class ApolloUsage {
9+
CodegenSchema,
10+
OtherOptions,
11+
Ir,
12+
CodegenMetadata
13+
}
14+
15+
internal enum class ApolloDirection {
16+
Upstream,
17+
Downstream
18+
}
19+
20+
internal enum class ConfigurationKind {
21+
DependencyScope,
22+
Consumable,
23+
Resolvable
24+
}

0 commit comments

Comments
 (0)