Skip to content

Commit

Permalink
chore: introduce 'qualityGate' task and clean up 'build' task group
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes committed Feb 8, 2024
1 parent d2c8ad5 commit fb368f1
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.component.AdhocComponentWithVariants
import org.gradle.kotlin.dsl.get

Expand All @@ -17,19 +33,13 @@ import org.gradle.kotlin.dsl.get
* limitations under the License.
*/

plugins {
id("java-test-fixtures")
}
plugins { id("java-test-fixtures") }

tasks.testFixturesJar { setGroup(null) }

// Disable publishing of test fixture if 'java-test-fixtures' plugin is used
// https://docs.gradle.org/current/userguide/java_testing.html#ex-disable-publishing-of-test-fixtures-variants
(components["java"] as AdhocComponentWithVariants).apply {
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) {
skip()
}
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) {
skip()
}
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ plugins {
id("jacoco")
id("checkstyle")
id("com.adarshr.test-logger")
id("com.hedera.hashgraph.lifecycle")
id("com.hedera.hashgraph.jpms-modules")
id("com.hedera.hashgraph.jpms-module-dependencies")
id("com.hedera.hashgraph.repositories")
Expand Down Expand Up @@ -60,7 +61,16 @@ configurations.getByName("mainRuntimeClasspath") { extendsFrom(internal.get()) }

dependencies { "internal"(platform("com.hedera.hashgraph:hedera-dependency-versions")) }

tasks.buildDependents { setGroup(null) }

tasks.buildNeeded { setGroup(null) }

tasks.jar { setGroup(null) }

sourceSets.all {
// Remove 'classes' tasks from 'build' group to keep it cleaned up
tasks.named(classesTaskName) { group = null }

configurations.getByName(compileClasspathConfigurationName) { extendsFrom(internal.get()) }
configurations.getByName(runtimeClasspathConfigurationName) { extendsFrom(internal.get()) }

Expand Down Expand Up @@ -162,6 +172,7 @@ testing {
useJUnitJupiter()
targets.all {
testTask {
group = "build"
maxHeapSize = "4g"
// Some tests overlap due to using the same temp folders within one project
// maxParallelForks = 4 <- set this, once tests can run in parallel
Expand All @@ -174,6 +185,7 @@ testing {
testType.set("hammer")
targets.all {
testTask {
group = "build"
shouldRunAfter(tasks.test)
usesService(
gradle.sharedServices.registerIfAbsent("lock", TaskLockService::class) {
Expand All @@ -190,6 +202,7 @@ testing {
testType.set("time-consuming")
targets.all {
testTask {
group = "build"
shouldRunAfter(tasks.test)
maxHeapSize = "16g"
}
Expand All @@ -201,6 +214,7 @@ testing {
testType.set(TestSuiteType.INTEGRATION_TEST)
targets.all {
testTask {
group = "build"
shouldRunAfter(tasks.test)
maxHeapSize = "8g"
addTestListener(testLogger())
Expand All @@ -213,6 +227,7 @@ testing {
testType.set("end-to-end-test")
targets.all {
testTask {
group = "build"
shouldRunAfter(tasks.test)
maxHeapSize = "8g"
}
Expand All @@ -232,6 +247,22 @@ testing {
}
}

// If user gave the argument '-PactiveProcessorCount', then do:
// - run all test tasks in sequence
// - give the -XX:ActiveProcessorCount argument to the test JVMs
val activeProcessorCount = providers.gradleProperty("activeProcessorCount")

if (activeProcessorCount.isPresent) {
tasks.withType<Test>().configureEach {
usesService(
gradle.sharedServices.registerIfAbsent("lock", TaskLockService::class) {
maxParallelUsages = 1
}
)
jvmArgs("-XX:ActiveProcessorCount=${activeProcessorCount.get()}")
}
}

tasks.jacocoTestReport {
// Configure Jacoco so it outputs XML reports (needed by SonarCloud)
reports {
Expand Down Expand Up @@ -263,6 +294,14 @@ tasks.assemble {

tasks.check { dependsOn(tasks.jacocoTestReport) }

tasks.named("qualityGate") { dependsOn(tasks.checkAllModuleInfo) }

tasks.withType<JavaCompile>() {
// When ding a 'qualityGate' run, make sure spotlessApply is done before doing compilation and
// other checks based on compiled code
mustRunAfter(tasks.spotlessApply)
}

// Do not report dependencies from one source set to another as 'required'.
// In particular, in case of test fixtures, the analysis would suggest to
// add as testModuleInfo { require(...) } to the main module. This is
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2016-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("base")
id("com.diffplug.spotless")
}

// Convenience for local development: when running './gradlew' without any parameters just show the
// tasks from the 'build' group
defaultTasks("tasks")

tasks.named<TaskReportTask>("tasks") {
if (!isDetail) {
displayGroup = "build"
}
}

tasks.register("qualityGate") {
group = "build"
description = "Apply spotless rules and run all quality checks."
dependsOn(tasks.spotlessApply)
dependsOn(tasks.assemble)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ java {
withSourcesJar()
}

tasks.withType<Jar>().configureEach { setGroup(null) }

val maven =
publishing.publications.create<MavenPublication>("maven") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Utils.Companion.versionTxt
import net.swiftzer.semver.SemVer

plugins {
id("com.hedera.hashgraph.lifecycle")
id("com.hedera.hashgraph.repositories")
id("com.hedera.hashgraph.aggregate-reports")
id("com.hedera.hashgraph.spotless-conventions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ tasks.test {

val timingSensitive =
tasks.register<Test>("timingSensitive") {
group = "build"
description = "Runs the timing sensitive tests of test suite."

// Separate target (task) for timingSensitive tests.
// Tests should eventually be fixed or moved to 'hammer'.
testClassesDirs = sourceSets.test.get().output.classesDirs
Expand Down
3 changes: 2 additions & 1 deletion hedera-node/hedera-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ tasks.register<JavaExec>("run") {
}

tasks.register<JavaExec>("modrun") {
group = "application"
group = "build"
description = "Run a Hedera consensus node instance."
dependsOn(tasks.assemble)
workingDir = nodeWorkingDir.get().asFile
jvmArgs = listOf("-cp", "data/lib/*:data/apps/*", "-Dhedera.workflows.enabled=true")
Expand Down

0 comments on commit fb368f1

Please sign in to comment.