Skip to content

Commit 3a3d121

Browse files
Refactor build scripts (#2116)
* Introduce a flag in gradle.properties to enable/disable testing (and the compilation of the associated dependencies). * Feature flag testing in all non-test-only build.gradle.kts files. * Remove dokka
1 parent 3e6adcd commit 3a3d121

File tree

7 files changed

+142
-120
lines changed

7 files changed

+142
-120
lines changed

aws/sdk-codegen/build.gradle.kts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ group = "software.amazon.software.amazon.smithy.rust.codegen.smithy"
1919
version = "0.1.0"
2020

2121
val smithyVersion: String by project
22-
val kotestVersion: String by project
2322

2423
dependencies {
2524
implementation(project(":codegen-core"))
2625
implementation(project(":codegen-client"))
27-
runtimeOnly(project(":aws:rust-runtime"))
2826
implementation("org.jsoup:jsoup:1.14.3")
2927
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
3028
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
3129
implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
32-
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
33-
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
3430
}
3531

3632
val generateAwsRuntimeCrateVersion by tasks.registering {
@@ -52,10 +48,6 @@ tasks.compileKotlin {
5248
dependsOn(generateAwsRuntimeCrateVersion)
5349
}
5450

55-
tasks.compileTestKotlin {
56-
kotlinOptions.jvmTarget = "1.8"
57-
}
58-
5951
// Reusable license copySpec
6052
val licenseSpec = copySpec {
6153
from("${project.rootDir}/LICENSE")
@@ -78,29 +70,44 @@ val sourcesJar by tasks.creating(Jar::class) {
7870
from(sourceSets.getByName("main").allSource)
7971
}
8072

81-
tasks.test {
82-
useJUnitPlatform()
83-
testLogging {
84-
events("passed", "skipped", "failed")
85-
exceptionFormat = TestExceptionFormat.FULL
86-
showCauses = true
87-
showExceptions = true
88-
showStackTraces = true
89-
showStandardStreams = true
73+
val isTestingEnabled: String by project
74+
if (isTestingEnabled.toBoolean()) {
75+
val kotestVersion: String by project
76+
77+
dependencies {
78+
runtimeOnly(project(":aws:rust-runtime"))
79+
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
80+
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
9081
}
91-
}
9282

93-
// Configure jacoco (code coverage) to generate an HTML report
94-
tasks.jacocoTestReport {
95-
reports {
96-
xml.required.set(false)
97-
csv.required.set(false)
98-
html.outputLocation.set(file("$buildDir/reports/jacoco"))
83+
tasks.compileTestKotlin {
84+
kotlinOptions.jvmTarget = "1.8"
9985
}
100-
}
10186

102-
// Always run the jacoco test report after testing.
103-
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
87+
tasks.test {
88+
useJUnitPlatform()
89+
testLogging {
90+
events("passed", "skipped", "failed")
91+
exceptionFormat = TestExceptionFormat.FULL
92+
showCauses = true
93+
showExceptions = true
94+
showStackTraces = true
95+
showStandardStreams = true
96+
}
97+
}
98+
99+
// Configure jacoco (code coverage) to generate an HTML report
100+
tasks.jacocoTestReport {
101+
reports {
102+
xml.required.set(false)
103+
csv.required.set(false)
104+
html.outputLocation.set(file("$buildDir/reports/jacoco"))
105+
}
106+
}
107+
108+
// Always run the jacoco test report after testing.
109+
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
110+
}
104111

105112
publishing {
106113
publications {

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ buildscript {
1616

1717
plugins {
1818
kotlin("jvm") version "1.3.72" apply false
19-
id("org.jetbrains.dokka") version "1.7.10"
2019
}
2120

2221
allprojects {

codegen-client/build.gradle.kts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
77

88
plugins {
99
kotlin("jvm")
10-
id("org.jetbrains.dokka")
1110
jacoco
1211
`maven-publish`
1312
}
@@ -20,7 +19,6 @@ group = "software.amazon.smithy.rust.codegen"
2019
version = "0.1.0"
2120

2221
val smithyVersion: String by project
23-
val kotestVersion: String by project
2422

2523
dependencies {
2624
implementation(project(":codegen-core"))
@@ -30,13 +28,6 @@ dependencies {
3028
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
3129
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
3230
implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
33-
runtimeOnly(project(":rust-runtime"))
34-
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
35-
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
36-
}
37-
38-
tasks.compileTestKotlin {
39-
kotlinOptions.jvmTarget = "1.8"
4031
}
4132

4233
tasks.compileKotlin {
@@ -65,36 +56,44 @@ val sourcesJar by tasks.creating(Jar::class) {
6556
from(sourceSets.getByName("main").allSource)
6657
}
6758

68-
tasks.test {
69-
useJUnitPlatform()
70-
testLogging {
71-
events("passed", "skipped", "failed")
72-
exceptionFormat = TestExceptionFormat.FULL
73-
showCauses = true
74-
showExceptions = true
75-
showStackTraces = true
76-
showStandardStreams = true
59+
val isTestingEnabled: String by project
60+
if (isTestingEnabled.toBoolean()) {
61+
val kotestVersion: String by project
62+
63+
dependencies {
64+
runtimeOnly(project(":rust-runtime"))
65+
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
66+
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
7767
}
78-
}
7968

80-
tasks.dokkaHtml.configure {
81-
outputDirectory.set(buildDir.resolve("javadoc"))
82-
}
69+
tasks.compileTestKotlin {
70+
kotlinOptions.jvmTarget = "1.8"
71+
}
8372

84-
// Always build documentation
85-
tasks["build"].finalizedBy(tasks["dokkaHtml"])
73+
tasks.test {
74+
useJUnitPlatform()
75+
testLogging {
76+
events("passed", "skipped", "failed")
77+
exceptionFormat = TestExceptionFormat.FULL
78+
showCauses = true
79+
showExceptions = true
80+
showStackTraces = true
81+
showStandardStreams = true
82+
}
83+
}
8684

87-
// Configure jacoco (code coverage) to generate an HTML report
88-
tasks.jacocoTestReport {
89-
reports {
90-
xml.required.set(false)
91-
csv.required.set(false)
92-
html.outputLocation.set(file("$buildDir/reports/jacoco"))
85+
// Configure jacoco (code coverage) to generate an HTML report
86+
tasks.jacocoTestReport {
87+
reports {
88+
xml.required.set(false)
89+
csv.required.set(false)
90+
html.outputLocation.set(file("$buildDir/reports/jacoco"))
91+
}
9392
}
94-
}
9593

96-
// Always run the jacoco test report after testing.
97-
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
94+
// Always run the jacoco test report after testing.
95+
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
96+
}
9897

9998
publishing {
10099
publications {

codegen-core/build.gradle.kts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.io.ByteArrayOutputStream
88

99
plugins {
1010
kotlin("jvm")
11-
id("org.jetbrains.dokka")
1211
jacoco
1312
`maven-publish`
1413
}
@@ -21,7 +20,6 @@ group = "software.amazon.smithy.rust.codegen"
2120
version = "0.1.0"
2221

2322
val smithyVersion: String by project
24-
val kotestVersion: String by project
2523

2624
dependencies {
2725
implementation(kotlin("stdlib-jdk8"))
@@ -31,9 +29,6 @@ dependencies {
3129
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
3230
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
3331
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
34-
runtimeOnly(project(":rust-runtime"))
35-
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
36-
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
3732
}
3833

3934
fun gitCommitHash(): String {
@@ -78,10 +73,6 @@ tasks.compileKotlin {
7873
dependsOn(generateSmithyRuntimeCrateVersion)
7974
}
8075

81-
tasks.compileTestKotlin {
82-
kotlinOptions.jvmTarget = "1.8"
83-
}
84-
8576
// Reusable license copySpec
8677
val licenseSpec = copySpec {
8778
from("${project.rootDir}/LICENSE")
@@ -104,36 +95,44 @@ val sourcesJar by tasks.creating(Jar::class) {
10495
from(sourceSets.getByName("main").allSource)
10596
}
10697

107-
tasks.test {
108-
useJUnitPlatform()
109-
testLogging {
110-
events("passed", "skipped", "failed")
111-
exceptionFormat = TestExceptionFormat.FULL
112-
showCauses = true
113-
showExceptions = true
114-
showStackTraces = true
115-
showStandardStreams = true
98+
val isTestingEnabled: String by project
99+
if (isTestingEnabled.toBoolean()) {
100+
val kotestVersion: String by project
101+
102+
dependencies {
103+
runtimeOnly(project(":rust-runtime"))
104+
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
105+
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
116106
}
117-
}
118107

119-
tasks.dokkaHtml.configure {
120-
outputDirectory.set(buildDir.resolve("javadoc"))
121-
}
108+
tasks.compileTestKotlin {
109+
kotlinOptions.jvmTarget = "1.8"
110+
}
122111

123-
// Always build documentation
124-
tasks["build"].finalizedBy(tasks["dokkaHtml"])
112+
tasks.test {
113+
useJUnitPlatform()
114+
testLogging {
115+
events("passed", "skipped", "failed")
116+
exceptionFormat = TestExceptionFormat.FULL
117+
showCauses = true
118+
showExceptions = true
119+
showStackTraces = true
120+
showStandardStreams = true
121+
}
122+
}
125123

126-
// Configure jacoco (code coverage) to generate an HTML report
127-
tasks.jacocoTestReport {
128-
reports {
129-
xml.required.set(false)
130-
csv.required.set(false)
131-
html.outputLocation.set(file("$buildDir/reports/jacoco"))
124+
// Configure jacoco (code coverage) to generate an HTML report
125+
tasks.jacocoTestReport {
126+
reports {
127+
xml.required.set(false)
128+
csv.required.set(false)
129+
html.outputLocation.set(file("$buildDir/reports/jacoco"))
130+
}
132131
}
133-
}
134132

135-
// Always run the jacoco test report after testing.
136-
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
133+
// Always run the jacoco test report after testing.
134+
tasks["test"].finalizedBy(tasks["jacocoTestReport"])
135+
}
137136

138137
publishing {
139138
publications {

codegen-server/build.gradle.kts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,15 @@ group = "software.amazon.smithy.rust.codegen.server.smithy"
2121
version = "0.1.0"
2222

2323
val smithyVersion: String by project
24-
val kotestVersion: String by project
2524

2625
dependencies {
2726
implementation(project(":codegen-core"))
2827
implementation(project(":codegen-client"))
2928
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
3029
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
31-
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
32-
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
3330
}
3431

3532
tasks.compileKotlin { kotlinOptions.jvmTarget = "1.8" }
36-
tasks.compileTestKotlin { kotlinOptions.jvmTarget = "1.8" }
3733

3834
// Reusable license copySpec
3935
val licenseSpec = copySpec {
@@ -55,15 +51,27 @@ val sourcesJar by tasks.creating(Jar::class) {
5551
from(sourceSets.getByName("main").allSource)
5652
}
5753

58-
tasks.test {
59-
useJUnitPlatform()
60-
testLogging {
61-
events("passed", "skipped", "failed")
62-
exceptionFormat = TestExceptionFormat.FULL
63-
showCauses = true
64-
showExceptions = true
65-
showStackTraces = true
66-
showStandardStreams = true
54+
val isTestingEnabled: String by project
55+
if (isTestingEnabled.toBoolean()) {
56+
val kotestVersion: String by project
57+
58+
dependencies {
59+
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
60+
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
61+
}
62+
63+
tasks.compileTestKotlin { kotlinOptions.jvmTarget = "1.8" }
64+
65+
tasks.test {
66+
useJUnitPlatform()
67+
testLogging {
68+
events("passed", "skipped", "failed")
69+
exceptionFormat = TestExceptionFormat.FULL
70+
showCauses = true
71+
showExceptions = true
72+
showStackTraces = true
73+
showStandardStreams = true
74+
}
6775
}
6876
}
6977

0 commit comments

Comments
 (0)