From 52ace95abf9cdae342da8bcb7752069a5970cc99 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Mon, 16 Sep 2024 09:13:26 +0200 Subject: [PATCH] build: cleanup settings.gradle.kts / remove build.gradle.kts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Protobuf versions are now also managed in 'hedera-dependency-versions' - Root 'build.gradle.kts' removed (config done in plugins) - Special project – 'hedera-dependency-versions' and 'reports' – are defined in plugins as they'll be the same in all Hedera projects Signed-off-by: Jendrik Johannes --- .../node-zxc-compile-application-code.yaml | 4 ++- build.gradle.kts | 17 ------------ .../com.hedera.gradle.lifecycle.gradle.kts | 6 ----- .../com.hedera.gradle.protobuf.gradle.kts | 26 +++++++------------ ...hedera.gradle.settings.settings.gradle.kts | 15 +++++++++++ hapi/build.gradle.kts | 2 +- hedera-dependency-versions/build.gradle.kts | 7 ++++- .../PlatformTestingTool/build.gradle.kts | 24 +++++++---------- settings.gradle.kts | 17 ------------ 9 files changed, 44 insertions(+), 74 deletions(-) delete mode 100644 build.gradle.kts diff --git a/.github/workflows/node-zxc-compile-application-code.yaml b/.github/workflows/node-zxc-compile-application-code.yaml index 963b273d4265..b490b85bfbbf 100644 --- a/.github/workflows/node-zxc-compile-application-code.yaml +++ b/.github/workflows/node-zxc-compile-application-code.yaml @@ -516,7 +516,9 @@ jobs: ) && !cancelled() }} - run: sed -i 's/^org.gradle.configuration-cache=.*$/org.gradle.configuration-cache=false/' gradle.properties + run: | + sed -i 's/^org.gradle.configuration-cache=.*$/org.gradle.configuration-cache=false/' gradle.properties + touch build.gradle.kts - name: Setup Snyk env: diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 9c998aff3795..000000000000 --- a/build.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2022-2023 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("com.hedera.gradle.root") } diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts index c0e1aa4fd83c..1c74e298998c 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts @@ -23,12 +23,6 @@ plugins { // tasks from the 'build' group defaultTasks("tasks") -tasks.named("tasks") { - if (!isDetail) { - displayGroup = "build" - } -} - tasks.register("qualityGate") { group = "build" description = "Apply spotless rules and run all quality checks." diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.protobuf.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.protobuf.gradle.kts index dd597a5bf671..1f2b29332f6c 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.protobuf.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.protobuf.gradle.kts @@ -23,31 +23,23 @@ plugins { // Configure Protobuf Plugin to download protoc executable rather than using local installed version protobuf { - val libs = the().named("libs") - protoc { artifact = "com.google.protobuf:protoc:" + libs.findVersion("google-proto").get() } + protoc { artifact = "com.google.protobuf:protoc" } plugins { // Add GRPC plugin as we need to generate GRPC services - id("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:" + libs.findVersion("grpc-proto").get() - } + id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java" } } generateProtoTasks { all().configureEach { plugins { id("grpc") { option("@generated=omit") } } } } } -sourceSets.all { - val compileProtoPath = getTaskName("", "compileProtoPath") - dependencies { - // For dependencies of protobuf compilation use versions from 'hedera-dependency-versions', - // but not 'runtime' dependencies of the platform (JAVA_API instead of JAVA_RUNTIME). - dependencies { - compileProtoPath(project(":hedera-dependency-versions")) { - attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.REGULAR_PLATFORM)) - } - } +configurations.configureEach { + if (name.startsWith("protobufToolsLocator") || name.endsWith("ProtoPath")) { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API)) } + exclude(group = project.group.toString(), module = project.name) + withDependencies { + isTransitive = true + extendsFrom(configurations["internal"]) } } } diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.settings.settings.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.settings.settings.gradle.kts index 3e3c4ccff566..295dbbe739e2 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.settings.settings.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.settings.settings.gradle.kts @@ -14,6 +14,9 @@ * limitations under the License. */ +import org.gradlex.javamodule.dependencies.initialization.JavaModulesExtension +import org.gradlex.javamodule.dependencies.initialization.RootPluginsExtension + pluginManagement { repositories { gradlePluginPortal() @@ -27,6 +30,10 @@ plugins { id("org.gradlex.java-module-dependencies") } +// Plugins that are global, but are applied to the "root project" instead of settings. +// by having this block here, we do not require a "build.gradle.kts" in the repository roots. +configure { id("com.hedera.gradle.root") } + // Enable Gradle Build Scan develocity { buildScan { @@ -63,3 +70,11 @@ buildCache { // https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions // Some functionality of the 'java-module-dependencies' plugin relies on this. includeBuild(".") + +configure { + // Project to aggregate code coverage data for the whole repository into one report + module("gradle/reports") + + // "BOM" with versions of 3rd party dependencies + versions("hedera-dependency-versions") +} diff --git a/hapi/build.gradle.kts b/hapi/build.gradle.kts index 038b71174a15..fae3da6548a2 100644 --- a/hapi/build.gradle.kts +++ b/hapi/build.gradle.kts @@ -18,7 +18,7 @@ plugins { id("com.hedera.gradle.protobuf") id("com.hedera.gradle.services-publish") id("com.hedera.gradle.feature.test-fixtures") - alias(libs.plugins.pbj) + id("com.hedera.pbj.pbj-compiler") version "0.9.2" } description = "Hedera API" diff --git a/hedera-dependency-versions/build.gradle.kts b/hedera-dependency-versions/build.gradle.kts index 5dcc2c77bf69..cc7021dfc2c3 100644 --- a/hedera-dependency-versions/build.gradle.kts +++ b/hedera-dependency-versions/build.gradle.kts @@ -22,7 +22,9 @@ dependencies { api(enforcedPlatform("io.netty:netty-bom:4.1.110.Final")) // forward logging from modules using SLF4J (e.g. 'org.hyperledger.besu.evm') to Log4J - runtime(javaModuleDependencies.gav("org.apache.logging.log4j.slf4j2.impl")) + runtime("org.apache.logging.log4j:log4j-slf4j2-impl") { + because("org.apache.logging.log4j.slf4j2.impl") + } } dependencies.constraints { @@ -221,4 +223,7 @@ dependencies.constraints { api("uk.org.webcompere:system-stubs-jupiter:2.1.5") { because("uk.org.webcompere.systemstubs.jupiter") } + + api("com.google.protobuf:protoc:3.25.4") + api("io.grpc:protoc-gen-grpc-java:1.66.0") } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts index 76903afdb2b0..5eddb4203445 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts @@ -14,8 +14,6 @@ * limitations under the License. */ -import com.google.protobuf.gradle.ProtobufExtract - plugins { id("com.hedera.gradle.application") id("com.hedera.gradle.feature.test-timing-sensitive") @@ -28,7 +26,7 @@ tasks.withType().configureEach { options.compilerArgs.add("-Xlint:-exports,-static,-cast") } -application.mainClass.set("com.swirlds.demo.platform.PlatformTestingToolMain") +application.mainClass = "com.swirlds.demo.platform.PlatformTestingToolMain" testModuleInfo { requires("org.apache.logging.log4j.core") @@ -51,17 +49,15 @@ timingSensitiveModuleInfo { requires("org.mockito") } -protobuf { protoc { artifact = "com.google.protobuf:protoc:3.21.5" } } - -configurations { - // Give proto compile access to the dependency versions - compileProtoPath { extendsFrom(configurations.internal.get()) } - testCompileProtoPath { extendsFrom(configurations.internal.get()) } - timingSensitiveCompileProtoPath { extendsFrom(configurations.internal.get()) } -} +protobuf { protoc { artifact = "com.google.protobuf:protoc" } } -tasks.withType().configureEach { - if (name == "extractIncludeProto") { - enabled = false +configurations.configureEach { + if (name.startsWith("protobufToolsLocator") || name.endsWith("ProtoPath")) { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API)) } + exclude(group = project.group.toString(), module = project.name) + withDependencies { + isTransitive = true + extendsFrom(configurations["internal"]) + } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 015ca3a49c55..83f80f05bf1e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,11 +18,7 @@ pluginManagement { includeBuild("gradle/plugins") } plugins { id("com.hedera.gradle.settings") } - javaModules { - // Project to aggregate code coverage data for the whole repository into one report´ - module("gradle/reports") - // This "intermediate parent project" should be removed module("platform-sdk") { artifact = "swirlds-platform" } @@ -81,17 +77,4 @@ javaModules { directory("platform-sdk/platform-apps/tests") { group = "com.swirlds" } - - // "BOM" with versions of 3rd party dependencies - versions("hedera-dependency-versions") -} - -dependencyResolutionManagement { - // Protobuf tool versions - versionCatalogs.create("libs") { - version("google-proto", "3.25.4") - version("grpc-proto", "1.66.0") - - plugin("pbj", "com.hedera.pbj.pbj-compiler").version("0.9.2") - } }