Skip to content

Commit

Permalink
exclude protobuf4 from grpc module
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Nov 20, 2024
1 parent f66fec7 commit f8215a7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,7 @@ allprojects {
}
}
}

configure(projectsWithFlags('java', 'publish')) {
failOnVersionConflict(libs.protobuf.java)
}
29 changes: 29 additions & 0 deletions gradle/scripts/lib/common-dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ allprojects { p ->
managedVersions = getManagedVersions(p.rootProject)
findLibrary = this.&findLibrary.curry(p.rootProject)
findPlugin = this.&findPlugin.curry(p.rootProject)
failOnVersionConflict = this.&failOnVersionConflict.curry(p)
}
}

Expand Down Expand Up @@ -331,3 +332,31 @@ final class GentlePlainTextReporter implements Reporter {
return delegate.getFileExtension()
}
}

/**
* A custom version of failOnVersionConflict which can limit which dependencies should be checked for conflict.
* Heavily inspired https://github.com/gradle/gradle/issues/8813.
*/
static def failOnVersionConflict(Project project, ProviderConvertible<MinimalExternalModuleDependency> providerConvertible) {
return failOnVersionConflict(project, providerConvertible.asProvider())
}

static def failOnVersionConflict(Project project, Provider<MinimalExternalModuleDependency> dependencyProvider) {
if (!dependencyProvider.isPresent()) {
return
}
def targetDependency = dependencyProvider.get()
project.configurations.configureEach { config ->
incoming.afterResolve {
resolutionResult.allComponents {ResolvedComponentResult result ->
if (selectionReason.conflictResolution && moduleVersion != null) {
// we don't care if the selected version is the one specified in dependencies.toml
if (targetDependency.module == moduleVersion.module && targetDependency.version != moduleVersion.version) {
throw new IllegalStateException("Project '${project.name}:${config.name}' resolution failed " +
"for '${targetDependency.module}' with '${getSelectionReason()}")
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ dependencies {
optionalImplementation libs.grpc.kotlin
optionalImplementation libs.kotlin.coroutines.core

api libs.protobuf.jackson
api(libs.protobuf.jackson) {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}

testImplementation(libs.gax.grpc) {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
Expand Down

0 comments on commit f8215a7

Please sign in to comment.