-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild.gradle
More file actions
126 lines (106 loc) · 5.17 KB
/
build.gradle
File metadata and controls
126 lines (106 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.nio.file.Files
import java.nio.file.Paths
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
plugins {
id 'java'
id 'idea'
id 'maven-publish'
}
group "org.logstash.outputs"
version Files.readAllLines(Paths.get("version")).first()
repositories {
mavenCentral()
}
def googleCloudBomVersion = '26.79.0'
dependencies {
implementation platform("com.google.cloud:libraries-bom:${googleCloudBomVersion}")
implementation 'com.google.cloud:google-cloud-pubsub'
}
task checkDependencyAlignment {
description = 'Verifies gRPC and Protobuf dependency versions are consistently resolved'
doLast {
def resolved = [:]
def declaredByPubsub = [:]
configurations.runtimeClasspath.resolvedConfiguration.firstLevelModuleDependencies.each { dep ->
if (dep.moduleGroup == 'com.google.cloud' && dep.moduleName == 'google-cloud-pubsub') {
dep.children.each { child ->
declaredByPubsub["${child.moduleGroup}:${child.moduleName}"] = child.moduleVersion
}
}
}
configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def id = artifact.moduleVersion.id
resolved["${id.group}:${id.name}"] = id.version
}
def grpcVersions = resolved.findAll { it.key.startsWith('io.grpc:grpc-') }
def uniqueGrpcVersions = grpcVersions.collect { it.value }.toSet()
if (grpcVersions.isEmpty()) {
throw new GradleException("No io.grpc modules found on runtimeClasspath")
}
if (uniqueGrpcVersions.size() > 1) {
def report = grpcVersions.sort().collect { k, v -> " ${k}: ${v}" }.join('\n')
throw new GradleException("gRPC version mismatch detected!\n${report}")
}
def pubsubGrpc = declaredByPubsub.find { it.key == 'io.grpc:grpc-api' }?.value
def resolvedGrpc = resolved['io.grpc:grpc-api']
if (pubsubGrpc && resolvedGrpc && pubsubGrpc != resolvedGrpc) {
throw new GradleException(
"google-cloud-pubsub expects gRPC ${pubsubGrpc}, but resolved to ${resolvedGrpc}. " +
"Ensure constraints align with the BOM-managed versions.")
}
def protobufJava = resolved['com.google.protobuf:protobuf-java']
def protobufUtil = resolved['com.google.protobuf:protobuf-java-util']
if (protobufJava && protobufUtil && protobufJava != protobufUtil) {
throw new GradleException(
"protobuf-java (${protobufJava}) and protobuf-java-util (${protobufUtil}) versions must match.")
}
def pubsubVersion = resolved['com.google.cloud:google-cloud-pubsub'] ?: 'N/A'
logger.lifecycle("google-cloud-pubsub: ${pubsubVersion}")
logger.lifecycle("gRPC: ${uniqueGrpcVersions.first()} (${grpcVersions.size()} modules)")
logger.lifecycle("Protobuf: protobuf-java=${protobufJava ?: 'N/A'}, protobuf-java-util=${protobufUtil ?: 'N/A'}")
}
}
task generateGemJarRequiresFile {
doLast {
File jars_file = file("lib/logstash-output-google_pubsub_jars.rb")
jars_file.newWriter().withWriter { w ->
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
w << "require \'jar_dependencies\'\n"
configurations.runtimeClasspath.incoming.artifacts.artifacts.each { artifact ->
def id = artifact.id.componentIdentifier
if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
w << "require_jar(\'${id.group}\', \'${id.module}\', \'${id.version}\')\n"
}
}
w << "require_jar(\'${project.group}\', \'${project.name}\', \'${project.version}\')\n"
}
}
}
task vendor {
doLast {
String vendorPathPrefix = "vendor/jar-dependencies"
configurations.runtimeClasspath.incoming.artifacts.artifacts.each { artifact ->
def id = artifact.id.componentIdentifier
if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
String group = id.group
String name = id.module
String version = id.version
String groupPath = group.replaceAll('\\.', '/')
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${name}/${version}/${name}-${version}.jar")
if (!newJarFile.parentFile.exists()) {
newJarFile.parentFile.mkdirs()
}
Files.copy(artifact.file.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
}
}
// Copy the project jar into vendor/jar-dependencies
String projectGroupPath = project.group.replaceAll('\\.', '/')
File projectJarFile = file("${vendorPathPrefix}/${projectGroupPath}/${project.name}/${project.version}/${project.name}-${project.version}.jar")
projectJarFile.mkdirs()
Files.copy(file("$buildDir/libs/${project.name}-${project.version}.jar").toPath(), projectJarFile.toPath(), REPLACE_EXISTING)
}
}
vendor.dependsOn(jar, generateGemJarRequiresFile, checkDependencyAlignment)
clean {
delete 'vendor/jar-dependencies'
}