|
| 1 | +final File buildNumberFile = file("${getLayout().buildDirectory.get()}/generated/build.number") |
| 2 | + |
| 3 | +allprojects { |
| 4 | + apply plugin: 'java-library' |
| 5 | + apply plugin: 'maven-publish' |
| 6 | + |
| 7 | + group 'io.airbyte.bulk-cdk' |
| 8 | + |
| 9 | + // Disable spotbugs on test code, which gets annoying really quickly for @MicronautTest classes. |
| 10 | + spotbugsTest { |
| 11 | + enabled = false |
| 12 | + } |
| 13 | + |
| 14 | + dependencies { |
| 15 | + implementation platform('org.jetbrains.kotlin:kotlin-bom:2.0.0') |
| 16 | + implementation platform('org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.8.1') |
| 17 | + implementation platform('com.fasterxml.jackson:jackson-bom:2.16.1') |
| 18 | + implementation platform('io.micronaut:micronaut-core-bom:4.3.13') |
| 19 | + implementation platform('org.junit:junit-bom:5.10.2') |
| 20 | + implementation platform('org.slf4j:slf4j-bom:2.0.13') |
| 21 | + implementation platform('org.apache.logging.log4j:log4j-bom:2.21.1') |
| 22 | + implementation platform('org.testcontainers:testcontainers-bom:1.19.8') |
| 23 | + |
| 24 | + implementation 'org.jetbrains.kotlin:kotlin-stdlib' |
| 25 | + implementation 'com.google.dagger:dagger-compiler:2.51.1' |
| 26 | + ksp 'com.google.dagger:dagger-compiler:2.51.1' |
| 27 | + |
| 28 | + annotationProcessor platform('io.micronaut:micronaut-core-bom:4.3.13') |
| 29 | + annotationProcessor 'info.picocli:picocli-codegen:4.7.5' |
| 30 | + annotationProcessor 'io.micronaut:micronaut-inject-kotlin' |
| 31 | + |
| 32 | + ksp platform('io.micronaut:micronaut-core-bom:4.3.13') |
| 33 | + ksp 'io.micronaut:micronaut-inject-kotlin' |
| 34 | + kspTest platform('io.micronaut:micronaut-core-bom:4.3.13') |
| 35 | + kspTest 'io.micronaut:micronaut-inject-kotlin' |
| 36 | + } |
| 37 | + |
| 38 | + if (buildNumberFile.exists()) { |
| 39 | + version = "0.${buildNumberFile.text.trim()}" |
| 40 | + publishing { |
| 41 | + publications { |
| 42 | + cdk(MavenPublication) { |
| 43 | + from components.java |
| 44 | + } |
| 45 | + } |
| 46 | + // This repository is only defined and used in the context of publishing artifacts |
| 47 | + // It's different from the 'airbyte-public-jars' defined in settings.gradle |
| 48 | + // only in its omission of the 'public' directory. |
| 49 | + // Any artifacts publish here will be available in the 'airbyte-public-jars' repo. |
| 50 | + repositories { |
| 51 | + maven { |
| 52 | + name 'airbyte-repo' |
| 53 | + url 'https://airbyte.mycloudrepo.io/repositories/airbyte-public-jars/' |
| 54 | + credentials { |
| 55 | + username System.getenv('CLOUDREPO_USER') |
| 56 | + password System.getenv('CLOUDREPO_PASSWORD') |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +if (buildNumberFile.exists()) { |
| 65 | + tasks.register('bulkCdkBuild').configure { |
| 66 | + dependsOn allprojects.collect {it.tasks.named('build')} |
| 67 | + } |
| 68 | + tasks.register('bulkCdkPublish').configure { |
| 69 | + dependsOn allprojects.collect {it.tasks.named('publish')} |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +tasks.register('generateBuildNumberFile') { |
| 74 | + description = 'Generates a build.number file in the build directory' |
| 75 | + group = 'Custom' |
| 76 | + outputs.file buildNumberFile |
| 77 | + |
| 78 | + doLast { |
| 79 | + var repoUrl = "https://airbyte.mycloudrepo.io/public/repositories/airbyte-public-jars" |
| 80 | + var groupIdUrl = "${repoUrl}/io/airbyte/bulk-cdk" |
| 81 | + var artifactUrl = "${groupIdUrl}/bulk" |
| 82 | + var metadataXmlUrl = "${artifactUrl}/maven-metadata.xml" |
| 83 | + |
| 84 | + var connection = metadataXmlUrl.toURL().openConnection() as HttpURLConnection |
| 85 | + try { |
| 86 | + connection.setRequestMethod("GET") |
| 87 | + connection.setDoInput(true) |
| 88 | + var responseCode = connection.getResponseCode() |
| 89 | + if (responseCode != 200) { |
| 90 | + throw new GradleException("Unexpected HTTP response code ${responseCode} from ${metadataXmlUrl} : expected 200.") |
| 91 | + } |
| 92 | + String responseContent = connection.inputStream.text |
| 93 | + def xml = new XmlParser().parseText(responseContent) |
| 94 | + String latestVersion = xml."versioning"."latest".text() |
| 95 | + String buildNumber = latestVersion.replaceFirst('^0\\.', '') |
| 96 | + Integer nextBuildNumber = 1 + buildNumber.toInteger() |
| 97 | + buildNumberFile.parentFile.mkdirs() |
| 98 | + buildNumberFile.text = "$nextBuildNumber" |
| 99 | + logger.lifecycle("Wrote Bulk CDK build number ${nextBuildNumber} to ${buildNumberFile.path}.") |
| 100 | + } finally { |
| 101 | + connection.disconnect() |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments