Skip to content

Commit

Permalink
build: add 'feature.legacy-classpath' plugin (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes authored Jan 17, 2025
1 parent ccd25e6 commit d395ad2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
}
65 changes: 65 additions & 0 deletions src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d395ad2

Please sign in to comment.