Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: patch everything we use to be a real Java Module #10056

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/project-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
implementation("net.swiftzer.semver:semver:1.3.0")
implementation("org.gradlex:extra-java-module-info:1.6")
implementation("org.gradlex:java-ecosystem-capabilities:1.3.1")
implementation("org.gradlex:java-module-dependencies:1.4.1")
implementation("org.gradlex:java-module-dependencies:1.5")
implementation("org.owasp:dependency-check-gradle:8.4.2")
implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:4.4.1.3373")
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ plugins {

group = "com.swirlds"

// Module Names of 'demo' projects do not always fit the expected pattern.
// Which is ok for the independent 'demo' projects that only consist of one project.
javaModuleDependencies.moduleNameCheck.set(false)

// Find the central SDK deployment dir by searching up the folder hierarchy
fun sdkDir(dir: Directory): Directory =
if (dir.dir("sdk").asFile.exists()) dir.dir("sdk") else sdkDir(dir.dir(".."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,6 @@

plugins { id("org.gradlex.java-module-dependencies") }

javaModuleDependencies {
warnForMissingVersions.set(false) // do not expect versions in catalog

// The following is not working because it looks for 'swirlds.test.framework'
// instead of 'swirlds-test-framework':
// moduleNamePrefixToGroup.put("com.", "com.swirlds")
// Hence, we list all 'swirlds' modules that are used outside the 'swirlds' build
moduleNameToGA.put("com.swirlds.base", "com.swirlds:swirlds-base")
moduleNameToGA.put("com.swirlds.cli", "com.swirlds:swirlds-cli")
moduleNameToGA.put("com.swirlds.common", "com.swirlds:swirlds-common")
moduleNameToGA.put(
"com.swirlds.common.test.fixtures",
"com.swirlds:swirlds-common|com.swirlds:swirlds-common-test-fixtures"
)
moduleNameToGA.put("com.swirlds.common.testing", "com.swirlds:swirlds-common-testing")
moduleNameToGA.put("com.swirlds.config.api", "com.swirlds:swirlds-config-api")
moduleNameToGA.put("com.swirlds.config.impl", "com.swirlds:swirlds-config-impl")
moduleNameToGA.put("com.swirlds.config.extensions", "com.swirlds:swirlds-config-extensions")
moduleNameToGA.put("com.swirlds.merkle.test", "com.swirlds:swirlds-merkle-test")
moduleNameToGA.put("com.swirlds.merkledb", "com.swirlds:swirlds-merkledb")
moduleNameToGA.put("com.swirlds.platform.core", "com.swirlds:swirlds-platform-core")
moduleNameToGA.put("com.swirlds.platform.gui", "com.swirlds:swirlds-platform-gui")
moduleNameToGA.put("com.swirlds.test.framework", "com.swirlds:swirlds-test-framework")

// Other Hedera modules
moduleNameToGA.put("com.hedera.pbj.runtime", "com.hedera.pbj:pbj-runtime")

// Third-party modules
moduleNameToGA.put(
"io.netty.transport.epoll.linux.x86_64",
"io.netty:netty-transport-native-epoll|io.netty:netty-transport-native-epoll-linux-x86_64"
)
moduleNameToGA.put(
"io.netty.transport.epoll.linux.aarch_64",
"io.netty:netty-transport-native-epoll|io.netty:netty-transport-native-epoll-linux-aarch_64"
)

// Testing only
moduleNameToGA.put("com.google.protobuf.util", "com.google.protobuf:protobuf-java-util")
moduleNameToGA.put("org.hamcrest", "org.hamcrest:hamcrest")
moduleNameToGA.put("org.mockito.junit.jupiter", "org.mockito:mockito-junit-jupiter")
moduleNameToGA.put("org.objenesis", "org.objenesis:objenesis")
}
// The following is required as long as we use different Module Name prefixes in the project. Right
// now we have 'com.hedera.node.' (works automatically) and 'com.' (for 'com.swirlds...' modules).
javaModuleDependencies { moduleNamePrefixToGroup.put("com.", "com.swirlds") }
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies.components {
withModule<RemoveAnnotationLibrariesMetadataRule>("com.github.ben-manes.caffeine:caffeine")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.github.spotbugs:spotbugs-annotations")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.google.dagger:dagger-compiler")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.google.dagger:dagger-producers")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.google.dagger:dagger-spi")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.google.guava:guava")
withModule<RemoveAnnotationLibrariesMetadataRule>("com.google.protobuf:protobuf-java-util")
Expand All @@ -44,9 +45,13 @@ dependencies.components {
withModule<IoPrometheusSimpleclientMetadataRule>("io.prometheus:simpleclient")

withModule<RemoveKotlinStdlibCommonMetadataRule>("org.jetbrains.kotlin:kotlin-stdlib")

withModule<RemoveHamcrestCoreMetadataRule>("junit:junit")
}

extraJavaModuleInfo {
failOnAutomaticModules.set(true) // Only allow Jars with 'module-info' on all module paths

module("io.grpc:grpc-netty", "grpc.netty") {
exportAllPackages()
requireAllDefinedDependencies()
Expand Down Expand Up @@ -89,9 +94,7 @@ extraJavaModuleInfo {
}
module("com.google.guava:guava", "com.google.common") {
exportAllPackages()
// requireAllDefinedDependencies() <- Currently not possible due to a Gradlex plugin
// limitation
requires("com.google.guava.failureaccess")
requireAllDefinedDependencies()
requires("java.logging")
}
module("com.google.guava:failureaccess", "com.google.guava.failureaccess") {
Expand Down Expand Up @@ -193,6 +196,9 @@ extraJavaModuleInfo {
module("io.netty:netty-common", "io.netty.common") {
exportAllPackages()
requireAllDefinedDependencies()
requires("java.logging")
requires("jdk.unsupported")
ignoreServiceProvider("reactor.blockhound.integration.BlockHoundIntegration")
}
module("io.netty:netty-handler", "io.netty.handler") {
exportAllPackages()
Expand Down Expand Up @@ -258,7 +264,6 @@ extraJavaModuleInfo {
exportAllPackages()
requireAllDefinedDependencies()
}

module("com.goterl:lazysodium-java", "lazysodium.java") {
exportAllPackages()
requireAllDefinedDependencies()
Expand All @@ -269,7 +274,7 @@ extraJavaModuleInfo {
}
module("net.java.dev.jna:jna", "com.sun.jna") {
exportAllPackages()
// no dependencies
requires("java.logging")
}
module("org.eclipse.collections:eclipse-collections-api", "org.eclipse.collections.api") {
exportAllPackages()
Expand Down Expand Up @@ -304,64 +309,181 @@ extraJavaModuleInfo {
"io.netty.transport.epoll.linux.aarch_64"
)

knownModule("com.github.ben-manes.caffeine:caffeine", "com.github.benmanes.caffeine")
knownModule("com.google.code.gson:gson", "com.google.gson")
knownModule("io.helidon.grpc:io.grpc", "io.grpc")
knownModule("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j")
knownModule("org.apache.logging.log4j:log4j-slf4j2-impl", "org.apache.logging.log4j.slf4j")
knownModule("org.bouncycastle:bcpkix-jdk18on", "org.bouncycastle.pkix")
knownModule("org.bouncycastle:bcprov-jdk18on", "org.bouncycastle.provider")
knownModule("org.bouncycastle:bcutil-jdk18on", "org.bouncycastle.util")
knownModule("org.jetbrains.kotlin:kotlin-stdlib-jdk8", "kotlin.stdlib.jdk8")
knownModule("org.slf4j:slf4j-api", "org.slf4j")
knownModule("jakarta.inject:jakarta.inject-api", "jakarta.inject")
knownModule("com.squareup:javapoet", "com.squareup.javapoet")
knownModule("com.google.auto.service:auto-service-annotations", "com.google.auto.service")

// Annotation processing only
automaticModule("com.google.dagger:dagger-compiler", "dagger.compiler")
automaticModule("com.google.dagger:dagger-producers", "dagger.producers")
automaticModule("com.google.dagger:dagger-spi", "dagger.spi")
automaticModule(
module("com.google.auto.service:auto-service-annotations", "com.google.auto.service") {
exportAllPackages()
// no dependencies
}
module("com.google.auto.service:auto-service", "com.google.auto.service.processor") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.auto:auto-common", "com.google.auto.common") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.dagger:dagger-compiler", "dagger.compiler") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.dagger:dagger-producers", "dagger.producers") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.dagger:dagger-spi", "dagger.spi") {
exportAllPackages()
requireAllDefinedDependencies()
}
module(
"com.google.devtools.ksp:symbol-processing-api",
"com.google.devtools.ksp.symbolprocessingapi"
)
automaticModule("com.google.errorprone:javac-shaded", "com.google.errorprone.javac.shaded")
automaticModule("com.google.googlejavaformat:google-java-format", "com.google.googlejavaformat")
automaticModule("net.ltgt.gradle.incap:incap", "net.ltgt.gradle.incap")
automaticModule("org.jetbrains.kotlinx:kotlinx-metadata-jvm", "kotlinx.metadata.jvm")
automaticModule("com.google.auto.service:auto-service", "com.google.auto.service.processor")
automaticModule("com.google.auto:auto-common", "com.google.auto.common")
) {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.errorprone:javac-shaded", "com.google.errorprone.javac.shaded") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.googlejavaformat:google-java-format", "com.google.googlejavaformat") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("net.ltgt.gradle.incap:incap", "net.ltgt.gradle.incap") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.jetbrains.kotlinx:kotlinx-metadata-jvm", "kotlinx.metadata.jvm") {
exportAllPackages()
requireAllDefinedDependencies()
}

// Testing only
automaticModule("com.google.jimfs:jimfs", "com.google.jimfs")
automaticModule("org.awaitility:awaitility", "awaitility")
automaticModule("org.hamcrest:hamcrest-core", "org.hamcrest.core")
automaticModule("org.mockito:mockito-inline", "org.mockito.inline")
automaticModule("uk.org.webcompere:system-stubs-core", "uk.org.webcompere.systemstubs.core")
automaticModule(
"uk.org.webcompere:system-stubs-jupiter",
"uk.org.webcompere.systemstubs.jupiter"
)
module("com.google.jimfs:jimfs", "com.google.jimfs") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.awaitility:awaitility", "awaitility") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.mockito:mockito-inline", "org.mockito.inline") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("uk.org.webcompere:system-stubs-core", "uk.org.webcompere.systemstubs.core") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("uk.org.webcompere:system-stubs-jupiter", "uk.org.webcompere.systemstubs.jupiter") {
exportAllPackages()
requireAllDefinedDependencies()
}

// JMH only
automaticModule("net.sf.jopt-simple:jopt-simple", "jopt.simple")
automaticModule("org.openjdk.jmh:jmh-core", "jmh.core")
automaticModule("org.openjdk.jmh:jmh-generator-asm", "jmh.generator.asm")
automaticModule("org.openjdk.jmh:jmh-generator-bytecode", "jmh.generator.bytecode")
automaticModule("org.openjdk.jmh:jmh-generator-reflection", "jmh.generator.reflection")
module("net.sf.jopt-simple:jopt-simple", "jopt.simple") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.openjdk.jmh:jmh-core", "jmh.core") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.openjdk.jmh:jmh-generator-asm", "jmh.generator.asm") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.openjdk.jmh:jmh-generator-bytecode", "jmh.generator.bytecode") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.openjdk.jmh:jmh-generator-reflection", "jmh.generator.reflection") {
exportAllPackages()
requireAllDefinedDependencies()
}

// Test clients only
automaticModule("com.github.docker-java:docker-java-api", "com.github.docker.java.api")
automaticModule(
"com.github.docker-java:docker-java-transport",
"com.github.docker.java.transport"
)
automaticModule(
module("com.github.docker-java:docker-java-api", "com.github.docker.java.api") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.github.docker-java:docker-java-transport", "com.github.docker.java.transport") {
exportAllPackages()
requireAllDefinedDependencies()
}
module(
"com.github.docker-java:docker-java-transport-zerodep",
"com.github.docker.transport.zerodep"
) {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.google.protobuf:protobuf-java-util", "com.google.protobuf.util") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.squareup:javapoet", "com.squareup.javapoet") {
exportAllPackages()
requires("java.compiler")
}
module("junit:junit", "junit") {
exportAllPackages()
// no dependencies
}
module("org.apache.commons:commons-compress", "org.apache.commons.compress") {
exportAllPackages()
// no dependencies
}
module("org.hamcrest:hamcrest", "org.hamcrest") {
exportAllPackages()
// no dependencies
}
module("org.json:json", "org.json") {
exportAllPackages()
// no dependencies
}
module("org.mockito:mockito-core", "org.mockito") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.objenesis:objenesis", "org.objenesis") {
exportAllPackages()
// no dependencies
}
module("org.rnorth.duct-tape:duct-tape", "org.rnorth.ducttape") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.testcontainers:junit-jupiter", "org.testcontainers.junit.jupiter") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.testcontainers:testcontainers", "org.testcontainers") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.mockito:mockito-junit-jupiter", "org.mockito.junit.jupiter") {
exportAllPackages()
requireAllDefinedDependencies()
}

// Jars that are not patched but to which Jars we patch above have 'requires'.
// If the 'requires' are created by requireAllDefinedDependencies(), the information
// how the library coordinates map to the Module Names is requires here.
knownModule(
"com.fasterxml.jackson.core:jackson-annotations",
"com.fasterxml.jackson.annotation"
)
automaticModule("org.rnorth.duct-tape:duct-tape", "org.rnorth.ducttape")
automaticModule("org.testcontainers:junit-jupiter", "org.testcontainers.junit.jupiter")
automaticModule("org.testcontainers:testcontainers", "org.testcontainers")
knownModule("com.github.ben-manes.caffeine:caffeine", "com.github.benmanes.caffeine")
knownModule("com.google.code.gson:gson", "com.google.gson")
knownModule("io.helidon.grpc:io.grpc", "io.grpc")
knownModule("net.bytebuddy:byte-buddy", "net.bytebuddy")
knownModule("net.bytebuddy:byte-buddy-agent", "net.bytebuddy.agent")
knownModule("org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j")
knownModule("org.bouncycastle:bcprov-jdk18on", "org.bouncycastle.provider")
knownModule("org.jetbrains.kotlin:kotlin-stdlib", "kotlin.stdlib")
knownModule("org.jetbrains.kotlin:kotlin-stdlib-jdk8", "kotlin.stdlib.jdk8")
knownModule("org.junit.jupiter:junit-jupiter-api", "org.junit.jupiter.api")
knownModule("org.ow2.asm:asm", "org.objectweb.asm")
knownModule("org.slf4j:slf4j-api", "org.slf4j")
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class RemoveAnnotationLibrariesMetadataRule : ComponentMetadataRule {
withDependencies {
removeAll { it.name == "animal-sniffer-annotations" }
removeAll { it.name == "checker-qual" }
removeAll { it.name == "checker-compat-qual" }
removeAll { it.name == "error_prone_annotations" }
removeAll { it.name == "j2objc-annotations" }
removeAll { it.name == "listenablefuture" }
Expand Down
Loading
Loading