gradle: overall simplification (#35307)
This commit is contained in:
@@ -4,20 +4,7 @@ plugins {
|
||||
|
||||
repositories {
|
||||
// # Gradle looks for dependency artifacts in repositories listed in 'repositories' blocks in descending order.
|
||||
|
||||
// ## Prefer repos controlled by Airbyte.
|
||||
// TODO: add airbyte-controlled proxy repos here
|
||||
|
||||
// ## Look into other, public repos.
|
||||
// Gradle plugin portal.
|
||||
gradlePluginPortal()
|
||||
// Maven Central has most of everything.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'ru.vyarus:gradle-use-python-plugin:2.3.0'
|
||||
implementation 'org.apache.commons:commons-text:1.10.0'
|
||||
}
|
||||
|
||||
tasks.withType(Jar).configureEach {
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
|
||||
class AirbyteIntegrationTestJavaPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
project.sourceSets {
|
||||
integrationTestJava {
|
||||
java {
|
||||
srcDir 'src/test-integration/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/test-integration/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
project.tasks.named('check').configure {
|
||||
dependsOn project.tasks.matching { it.name == 'compileIntegrationTestJavaJava' }
|
||||
dependsOn project.tasks.matching { it.name == 'spotbugsIntegrationTestJava' }
|
||||
}
|
||||
|
||||
project.configurations {
|
||||
integrationTestJavaImplementation.extendsFrom testImplementation
|
||||
integrationTestJavaRuntimeOnly.extendsFrom testRuntimeOnly
|
||||
}
|
||||
|
||||
def integrationTestJava = project.tasks.register('integrationTestJava', Test) {
|
||||
testClassesDirs = project.sourceSets.integrationTestJava.output.classesDirs
|
||||
classpath += project.sourceSets.integrationTestJava.runtimeClasspath
|
||||
|
||||
useJUnitPlatform()
|
||||
testLogging() {
|
||||
events 'skipped', 'started', 'passed', 'failed'
|
||||
exceptionFormat 'full'
|
||||
// Swallow the logs when running in airbyte-ci, rely on test reports instead.
|
||||
showStandardStreams = !System.getenv().containsKey("RUN_IN_AIRBYTE_CI")
|
||||
}
|
||||
|
||||
jvmArgs = project.test.jvmArgs
|
||||
systemProperties = project.test.systemProperties
|
||||
maxParallelForks = project.test.maxParallelForks
|
||||
maxHeapSize = project.test.maxHeapSize
|
||||
|
||||
// Tone down the JIT when running the containerized connector to improve overall performance.
|
||||
// The JVM default settings are optimized for long-lived processes in steady-state operation.
|
||||
// Unlike in production, the connector containers in these tests are always short-lived.
|
||||
// It's very much worth injecting a JAVA_OPTS environment variable into the container with
|
||||
// flags which will reduce startup time at the detriment of long-term performance.
|
||||
environment 'JOB_DEFAULT_ENV_JAVA_OPTS', '-XX:TieredStopAtLevel=1'
|
||||
|
||||
// Always re-run integration tests no matter what.
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
integrationTestJava.configure {
|
||||
mustRunAfter project.tasks.named('check')
|
||||
dependsOn project.tasks.matching { it.name == 'assemble' }
|
||||
}
|
||||
project.tasks.named('build').configure {
|
||||
dependsOn integrationTestJava
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
This class facilites detecting the Java CDK target version via readCdkTargetVersion().
|
||||
*/
|
||||
|
||||
import java.util.Properties
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
|
||||
class AirbyteJavaCdkPlugin implements Plugin<Project> {
|
||||
|
||||
static String CDK_VERSION_FILE = "airbyte-cdk/java/airbyte-cdk/core/src/main/resources/version.properties"
|
||||
|
||||
String readCdkTargetVersion(Project project) {
|
||||
Properties cdkVersionProps = new Properties()
|
||||
project.file("${project.rootDir}/${CDK_VERSION_FILE}").withInputStream {
|
||||
cdkVersionProps.load(it)
|
||||
}
|
||||
return cdkVersionProps.getProperty('version') ?: 'undefined'
|
||||
}
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
project.ext.getCdkTargetVersion = {
|
||||
return readCdkTargetVersion(project)
|
||||
}
|
||||
project.getTasks().create("disableLocalCdkRefs", DisableLocalCdkRefsTask.class)
|
||||
project.getTasks().create("assertNotUsingLocalCdk", AssertNotUsingLocalCdkTask.class)
|
||||
}
|
||||
|
||||
public static class DisableLocalCdkRefsTask extends DefaultTask {
|
||||
@TaskAction
|
||||
public void disableLocalCdkRefs() {
|
||||
// Step through the project tree and set useLocalCdk to false on all connectors
|
||||
getProject().rootProject.fileTree(dir: '.', include: '**/build.gradle').forEach(file -> {
|
||||
String content = file.getText()
|
||||
if (content.contains("useLocalCdk = true")) {
|
||||
content = content.replace("useLocalCdk = true", "useLocalCdk = false")
|
||||
file.setText(content)
|
||||
System.out.println("Updated " + file.getPath())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public static class AssertNotUsingLocalCdkTask extends DefaultTask {
|
||||
@TaskAction
|
||||
public void assertNotUsingLocalCdk() {
|
||||
List<String> foundPaths = new ArrayList<>()
|
||||
|
||||
for (File file : getProject().rootProject.fileTree(dir: '.', include: '**/build.gradle')) {
|
||||
String content = file.getText()
|
||||
if (content.contains("useLocalCdk = true")) {
|
||||
System.err.println("Found usage of 'useLocalCdk = true' in " + file.getPath())
|
||||
foundPaths.add(file.getPath())
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundPaths.isEmpty()) {
|
||||
String errorMessage = String.format(
|
||||
"Detected usage of 'useLocalCdk = true' in the following files:\n%s\n" +
|
||||
"This must be set to 'false' before merging to the main branch. \n" +
|
||||
"NOTE: You can run './gradlew disableLocalCdkRefs' to automatically set it to 'false' on all projects.",
|
||||
String.join("\n", foundPaths)
|
||||
)
|
||||
throw new RuntimeException(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ Also facilitates importing and working with the Java CDK.
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
|
||||
class AirbyteJavaConnectorExtension {
|
||||
|
||||
@@ -125,13 +126,106 @@ class AirbyteJavaConnectorPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
|
||||
project.plugins.apply('application')
|
||||
project.plugins.apply('java-test-fixtures')
|
||||
project.plugins.apply(AirbyteIntegrationTestJavaPlugin)
|
||||
project.plugins.apply(AirbytePerformanceTestJavaPlugin)
|
||||
|
||||
project.sourceSets {
|
||||
integrationTestJava {
|
||||
java {
|
||||
srcDir 'src/test-integration/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/test-integration/resources'
|
||||
}
|
||||
}
|
||||
performanceTestJava {
|
||||
java {
|
||||
srcDir 'src/test-performance/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/test-performance/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.tasks.named('check').configure {
|
||||
dependsOn project.tasks.matching { it.name ==~ /(compile|spotbugs)[a-zA-Z]*Java/ }
|
||||
}
|
||||
|
||||
project.configurations {
|
||||
testFixturesImplementation.extendsFrom implementation
|
||||
testFixturesRuntimeOnly.extendsFrom runtimeOnly
|
||||
integrationTestJavaImplementation.extendsFrom testImplementation
|
||||
integrationTestJavaRuntimeOnly.extendsFrom testRuntimeOnly
|
||||
performanceTestJavaImplementation.extendsFrom testImplementation
|
||||
performanceTestJavaRuntimeOnly.extendsFrom testRuntimeOnly
|
||||
}
|
||||
|
||||
boolean withSlowTests = System.getProperty('skipSlowTests', 'false') == 'false'
|
||||
project.test {
|
||||
onlyIf { withSlowTests }
|
||||
}
|
||||
|
||||
def integrationTestJava = project.tasks.register('integrationTestJava', Test) {
|
||||
testClassesDirs = project.sourceSets.integrationTestJava.output.classesDirs
|
||||
classpath += project.sourceSets.integrationTestJava.runtimeClasspath
|
||||
|
||||
useJUnitPlatform()
|
||||
testLogging() {
|
||||
events 'skipped', 'started', 'passed', 'failed'
|
||||
exceptionFormat 'full'
|
||||
// Swallow the logs when running in airbyte-ci, rely on test reports instead.
|
||||
showStandardStreams = !System.getenv().containsKey("RUN_IN_AIRBYTE_CI")
|
||||
}
|
||||
|
||||
jvmArgs = project.test.jvmArgs
|
||||
systemProperties = project.test.systemProperties
|
||||
maxParallelForks = project.test.maxParallelForks
|
||||
maxHeapSize = project.test.maxHeapSize
|
||||
|
||||
// Tone down the JIT when running the containerized connector to improve overall performance.
|
||||
// The JVM default settings are optimized for long-lived processes in steady-state operation.
|
||||
// Unlike in production, the connector containers in these tests are always short-lived.
|
||||
// It's very much worth injecting a JAVA_OPTS environment variable into the container with
|
||||
// flags which will reduce startup time at the detriment of long-term performance.
|
||||
environment 'JOB_DEFAULT_ENV_JAVA_OPTS', '-XX:TieredStopAtLevel=1'
|
||||
|
||||
// Always re-run integration tests no matter what.
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
integrationTestJava.configure {
|
||||
mustRunAfter project.tasks.named('check')
|
||||
dependsOn project.tasks.matching { it.name == 'assemble' }
|
||||
onlyIf { withSlowTests }
|
||||
}
|
||||
project.tasks.register('integrationTest').configure {
|
||||
dependsOn integrationTestJava
|
||||
}
|
||||
project.tasks.named('build').configure {
|
||||
dependsOn integrationTestJava
|
||||
}
|
||||
|
||||
def performanceTestJava = project.tasks.register('performanceTestJava', Test) {
|
||||
testClassesDirs = project.sourceSets.performanceTestJava.output.classesDirs
|
||||
classpath += project.sourceSets.performanceTestJava.runtimeClasspath
|
||||
|
||||
systemProperty "cpuLimit", System.getProperty("cpuLimit")
|
||||
systemProperty "memoryLimit", System.getProperty("memoryLimit")
|
||||
useJUnitPlatform()
|
||||
testLogging() {
|
||||
events "passed", "failed"
|
||||
exceptionFormat "full"
|
||||
showStandardStreams = true
|
||||
}
|
||||
|
||||
outputs.upToDateWhen { false }
|
||||
maxHeapSize = '3g'
|
||||
}
|
||||
performanceTestJava.configure {
|
||||
mustRunAfter project.tasks.named('check')
|
||||
dependsOn project.tasks.matching { it.name == 'assemble' }
|
||||
onlyIf { withSlowTests }
|
||||
}
|
||||
project.tasks.register('performanceTest').configure {
|
||||
dependsOn performanceTestJava
|
||||
}
|
||||
|
||||
project.dependencies {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
|
||||
class AirbytePerformanceTestJavaPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
project.sourceSets {
|
||||
performanceTestJava {
|
||||
java {
|
||||
srcDir 'src/test-performance/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/test-performance/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
project.tasks.named('check').configure {
|
||||
dependsOn project.tasks.matching { it.name == 'compilePerformanceTestJavaJava' }
|
||||
dependsOn project.tasks.matching { it.name == 'spotbugsPerformanceTestJava' }
|
||||
}
|
||||
|
||||
project.configurations {
|
||||
performanceTestJavaImplementation.extendsFrom testImplementation
|
||||
performanceTestJavaRuntimeOnly.extendsFrom testRuntimeOnly
|
||||
}
|
||||
|
||||
def performanceTestJava = project.tasks.register('performanceTestJava', Test) {
|
||||
testClassesDirs = project.sourceSets.performanceTestJava.output.classesDirs
|
||||
classpath += project.sourceSets.performanceTestJava.runtimeClasspath
|
||||
|
||||
systemProperty "cpuLimit", System.getProperty("cpuLimit")
|
||||
systemProperty "memoryLimit", System.getProperty("memoryLimit")
|
||||
useJUnitPlatform()
|
||||
testLogging() {
|
||||
events "passed", "failed"
|
||||
exceptionFormat "full"
|
||||
showStandardStreams = true
|
||||
}
|
||||
|
||||
outputs.upToDateWhen { false }
|
||||
maxHeapSize = '3g'
|
||||
}
|
||||
performanceTestJava.configure {
|
||||
mustRunAfter project.tasks.named('check')
|
||||
dependsOn project.tasks.matching { it.name == 'assemble' }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user