Skip to content
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

Added exclude rule with dependsOn #6343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import com.apollographql.apollo.compiler.PackageNameGenerator
import org.gradle.api.Action
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ExcludeRule
import org.gradle.api.component.SoftwareComponent
import org.gradle.api.file.ConfigurableFileCollection
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.internal.artifacts.DefaultExcludeRule
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -775,16 +777,19 @@ interface Service {
/**
* Adds a dependency for the codegen. Use this when some types/fragments are generated
* in upstream modules.
*
* @param excludeRules List of [DefaultExcludeRule] to specify which dependencies should be excluded.
* Each rule can define group and/or module to exclude.
* Default is an empty list, meaning no exclusions.
*/
fun dependsOn(dependencyNotation: Any)
fun dependsOn(dependencyNotation: Any, excludeRules: List<DefaultExcludeRule> = emptyList())

/**
* Counterpoint of [dependsOn]. [isADependencyOf] allows a schema module to discover
* used types in downstream modules automatically without having to specify [alwaysGenerateTypesMatching].
*
* This works by setting a dependency on the IR in downstream modules.
* Because the IR task and the codegen task are separate this does not create a cycle.
*
* @see [alwaysGenerateTypesMatching]
*/
fun isADependencyOf(dependencyNotation: Any)
Expand All @@ -797,9 +802,13 @@ interface Service {
*
* @param bidirectional if true and if [dependencyNotation] is a project dependency,
* automatically configure the symmetrical dependency for automatic detection of used types.
*
* @param excludeRules List of [DefaultExcludeRule] to specify which dependencies should be excluded.
* Each rule can define group and/or module to exclude.
* Default is an empty list, meaning no exclusions.
*/
@ApolloExperimental
fun dependsOn(dependencyNotation: Any, bidirectional: Boolean)
fun dependsOn(dependencyNotation: Any, bidirectional: Boolean, excludeRules: List<DefaultExcludeRule> = emptyList())

class OperationOutputConnection(
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.ConfigurableFileTree
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.internal.artifacts.DefaultExcludeRule
import org.gradle.api.artifacts.ModuleDependency
import java.io.File
import javax.inject.Inject

Expand Down Expand Up @@ -199,12 +201,19 @@ abstract class DefaultService @Inject constructor(val project: Project, override

override fun mapScalarToUpload(graphQLName: String) = mapScalar(graphQLName, "com.apollographql.apollo.api.Upload", "com.apollographql.apollo.api.UploadAdapter")

override fun dependsOn(dependencyNotation: Any) {
dependsOn(dependencyNotation, false)
override fun dependsOn(dependencyNotation: Any, excludeRules: List<DefaultExcludeRule>) {
dependsOn(dependencyNotation, false, excludeRules)
}

override fun dependsOn(dependencyNotation: Any, bidirectional: Boolean) {
upstreamDependencies.add(project.dependencies.create(dependencyNotation))
override fun dependsOn(dependencyNotation: Any, bidirectional: Boolean, excludeRules: List<DefaultExcludeRule>) {
upstreamDependencies.add(project.dependencies.create(dependencyNotation).apply {
if (this is ModuleDependency) {
excludeRules.forEach { rule ->
exclude(mapOf("group" to rule.group).plus(mapOf("module" to rule.module)))
}
}
})

if (bidirectional) {
val upstreamProject = when (dependencyNotation) {
is ProjectDependency -> project.rootProject.project(dependencyNotation.getPathCompat())
Expand Down
Loading