From 010724ac71b21b8cef5c11bb196c057b6992280a Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Fri, 17 Jan 2025 08:10:21 +0100 Subject: [PATCH] build: add 'feature.legacy-classpath' plugin Signed-off-by: Jendrik Johannes --- CHANGELOG.md | 1 + ....hiero.gradle.feature.legacy-classpath.txt | 1 + ...gradle.feature.legacy-classpath.gradle.kts | 11 ++++ .../hiero/gradle/test/LegacyClasspathTest.kt | 65 +++++++++++++++++++ .../gradle/test/fixtures/GradleProject.kt | 4 +- 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/main/descriptions/org.hiero.gradle.feature.legacy-classpath.txt create mode 100644 src/main/kotlin/org.hiero.gradle.feature.legacy-classpath.gradle.kts create mode 100644 src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 54229c4..ac1159f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * deactivate signing for Gradle plugin publishing if not explicitly turned on * update spotless-plugin-gradle to 7.0.2 (improves configuration cache compatibility) * update dependency-analysis-gradle-plugin to 2.7.0 (addresses Gradle deprecation) +* add 'feature.legacy-classpath' convention plugin ## Version 0.3.0 diff --git a/src/main/descriptions/org.hiero.gradle.feature.legacy-classpath.txt b/src/main/descriptions/org.hiero.gradle.feature.legacy-classpath.txt new file mode 100644 index 0000000..3134b92 --- /dev/null +++ b/src/main/descriptions/org.hiero.gradle.feature.legacy-classpath.txt @@ -0,0 +1 @@ +Conventions to allow non-module Jars on the classpath if a framework is used that is not yet JPMS compatible (e.g. has split packages) \ No newline at end of file diff --git a/src/main/kotlin/org.hiero.gradle.feature.legacy-classpath.gradle.kts b/src/main/kotlin/org.hiero.gradle.feature.legacy-classpath.gradle.kts new file mode 100644 index 0000000..41f3d3d --- /dev/null +++ b/src/main/kotlin/org.hiero.gradle.feature.legacy-classpath.gradle.kts @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: Apache-2.0 +plugins { id("org.hiero.gradle.base.jpms-modules") } + +// Make sure 'org.gradlex.java-module-dependencies' is applied as the auto-apply through settings +// may not happen in a non-module project +apply(plugin = "org.gradlex.java-module-dependencies") + +extraJavaModuleInfo { + failOnMissingModuleInfo = false + failOnAutomaticModules = false +} diff --git a/src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt b/src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt new file mode 100644 index 0000000..861bbe6 --- /dev/null +++ b/src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 +package org.hiero.gradle.test + +import org.assertj.core.api.Assertions.assertThat +import org.gradle.testkit.runner.TaskOutcome +import org.hiero.gradle.test.fixtures.GradleProject +import org.junit.jupiter.api.Test + +class LegacyClasspathTest { + + @Test + fun `can build a classpath-based application`() { + val p = GradleProject().withMinimalStructure() + p.moduleInfo.delete() + // explicitly register Module without module-info + p.settingsFile.appendText("""javaModules { module("product/module-a") }""") + p.dependencyVersionsFile( + """ + plugins { + id("org.hiero.gradle.base.lifecycle") + id("org.hiero.gradle.base.jpms-modules") + } + dependencies { api(platform("com.google.cloud:libraries-bom:26.49.0")) } + """ + .trimIndent() + ) + p.aggregationBuildFile( + """ + plugins { id("java") } + dependencies { implementation(project(":module-a")) } + """ + .trimIndent() + ) + p.file( + "gradle/modules.properties", + """ + # Jars that are not yet modules + com.google.api.gax=com.google.api:gax + com.google.auth.oauth2=com.google.auth:google-auth-library-oauth2-http + com.google.cloud.core=com.google.cloud:google-cloud-core + com.google.cloud.storage=com.google.cloud:google-cloud-storage + """ + .trimIndent() + ) + p.moduleBuildFile( + """ + plugins { + id("org.hiero.gradle.module.application") + id("org.hiero.gradle.feature.legacy-classpath") + } + mainModuleInfo { + requires("com.google.api.gax") + requires("com.google.auth.oauth2") + requires("com.google.cloud.core") + requires("com.google.cloud.storage") + } + """ + .trimIndent() + ) + + val result = p.run("assemble") + + assertThat(result.task(":module-a:assemble")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } +} diff --git a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt index d5ec238..0c24257 100644 --- a/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt +++ b/src/test/kotlin/org/hiero/gradle/test/fixtures/GradleProject.kt @@ -25,7 +25,7 @@ class GradleProject { val descriptionTxt = file("product/description.txt") val moduleBuildFile = file("product/module-a/build.gradle.kts") - private val moduleInfo = file("product/module-a/src/main/java/module-info.java") + val moduleInfo = file("product/module-a/src/main/java/module-info.java") private val javaSourceFile = file("product/module-a/src/main/java/org/hiero/product/module/a/ModuleA.java") @@ -61,7 +61,7 @@ class GradleProject { ) aggregation.writeFormatted("""plugins { id("org.hiero.gradle.base.lifecycle") }""") versionFile.writeText("1.0") - toolchainVersionsFile.writeText("jdk=17.0.12") + toolchainVersionsFile.writeText("jdk=17.0.13") descriptionTxt.writeText("A module to test hiero-gradle-conventions") moduleInfoFile("module org.hiero.product.module.a {}") javaSourceFile(