Skip to content

Commit ff31b44

Browse files
author
Marius Posta
authored
gradle: add airbyte-bulk-connector plugin (#44834)
1 parent bf56f30 commit ff31b44

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
4+
class AirbyteBulkConnectorExtension {
5+
6+
String core // 'extract' or 'load'
7+
List<String> toolkits = [] // 'extract-jdbc', etc...
8+
String cdk // 'local' or a specific version
9+
10+
AirbyteBulkConnectorExtension(Project project) {
11+
this.project = project
12+
}
13+
14+
private Project project
15+
16+
void setCore(String core) {
17+
this.core = core
18+
if (core != "extract" && core != "load") {
19+
throw new IllegalArgumentException("'core' should be either 'extract' or 'load'")
20+
}
21+
if (cdk != null) {
22+
throw new IllegalArgumentException("'core' should be defined before 'cdk'")
23+
}
24+
}
25+
26+
void setToolkits(List<String> toolkits) {
27+
this.toolkits = toolkits
28+
if (cdk != null) {
29+
throw new IllegalArgumentException("'toolkits' should be defined before 'cdk'")
30+
}
31+
}
32+
33+
void setCdk(String cdk) {
34+
this.cdk = cdk
35+
if (cdk != "local" && !cdk.matches("^[0-9]+\\.[0-9]+")) {
36+
throw new IllegalArgumentException("'cdk' should be either a well-formed version number or 'local'")
37+
}
38+
39+
project.processResources {
40+
// The metadata.yaml file is required by Micronaut.
41+
from(project.projectDir) {
42+
include 'metadata.yaml'
43+
duplicatesStrategy DuplicatesStrategy.EXCLUDE
44+
}
45+
}
46+
47+
List<Project> fromSource = []
48+
List<String> fromJar = []
49+
if (cdk == "local") {
50+
fromSource = [
51+
project.project(":airbyte-cdk:bulk:core:bulk-cdk-core-base"),
52+
project.project(":airbyte-cdk:bulk:core:bulk-cdk-core-$core"),
53+
]
54+
for (toolkit in toolkits) {
55+
fromSource << project.project(":airbyte-cdk:bulk:toolkits:bulk-cdk-toolkit-$toolkit")
56+
}
57+
} else {
58+
fromJar = [
59+
"io.airbyte.bulk-cdk:bulk-cdk-core-base:$cdk",
60+
"io.airbyte.bulk-cdk:bulk-cdk-core-$core:$cdk",
61+
]
62+
for (toolkit in toolkits) {
63+
fromJar << "io.airbyte.bulk-cdk:bulk-cdk-toolkit-$toolkit:$cdk"
64+
}
65+
}
66+
67+
String micronautVersion = null
68+
{
69+
// Use a temporary configuration to find the Micronaut version
70+
// in the transitive dependencies of the Bulk CDK base.
71+
def tempConfiguration = project.configurations.detachedConfiguration()
72+
def baseDependency = (cdk == "local")
73+
? project.dependencies.create(fromSource.first)
74+
: project.dependencies.create(fromJar.first)
75+
tempConfiguration.dependencies.add(baseDependency)
76+
tempConfiguration.resolvedConfiguration.firstLevelModuleDependencies.each {resolvedDependency ->
77+
resolvedDependency.children.each { transitiveDependency ->
78+
if (micronautVersion == null &&
79+
transitiveDependency.moduleGroup == TARGET_GROUP &&
80+
transitiveDependency.moduleName == TARGET_MODULE) {
81+
micronautVersion = transitiveDependency.moduleVersion
82+
}
83+
}
84+
}
85+
if (micronautVersion == null) {
86+
throw new IllegalArgumentException(
87+
"Micronaut version number not found; $TARGET_GROUP:$TARGET_MODULE is not a transitive dependency."
88+
)
89+
}
90+
}
91+
final String kspDependency = "io.micronaut:micronaut-inject-kotlin:$micronautVersion"
92+
93+
project.dependencies {
94+
95+
ksp kspDependency
96+
kspTestFixtures kspDependency
97+
kspTest kspDependency
98+
99+
for (dep in fromSource) {
100+
implementation dep
101+
testFixturesImplementation dep
102+
testFixturesImplementation testFixtures(dep)
103+
testImplementation dep
104+
testImplementation testFixtures(dep)
105+
}
106+
for (dep in fromJar) {
107+
implementation dep
108+
testFixturesImplementation dep
109+
testFixturesImplementation testFixtures(dep)
110+
testImplementation dep
111+
testImplementation testFixtures(dep)
112+
}
113+
}
114+
}
115+
116+
static private final String TARGET_GROUP = "io.micronaut"
117+
static private final String TARGET_MODULE = "micronaut-runtime"
118+
}
119+
120+
class AirbyteBulkConnectorPlugin implements Plugin<Project> {
121+
122+
@Override
123+
void apply(Project project) {
124+
125+
project.plugins.apply('application')
126+
127+
project.application {
128+
applicationDefaultJvmArgs = [
129+
'-XX:+ExitOnOutOfMemoryError',
130+
'-XX:InitialRAMPercentage=75.0',
131+
'-XX:MaxRAMPercentage=75.0',
132+
]
133+
}
134+
135+
project.tasks.named('spotbugsTest').configure {
136+
enabled = false
137+
}
138+
139+
project.tasks.named('check').configure {
140+
dependsOn project.tasks.matching { it.name ==~ /(compile|spotbugs)[a-zA-Z]*Java/ }
141+
}
142+
143+
project.configurations {
144+
testFixturesImplementation.extendsFrom implementation
145+
testFixturesRuntimeOnly.extendsFrom runtimeOnly
146+
}
147+
148+
project.extensions.create('airbyteBulkConnector', AirbyteBulkConnectorExtension, project)
149+
}
150+
}

0 commit comments

Comments
 (0)