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: add 'feature.legacy-classpath' plugin #85

Merged
merged 1 commit into from
Jan 17, 2025
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
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 {

Check warning on line 9 in src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt#L9

LegacyClasspathTest is missing required documentation.

@Test
fun `can build a classpath-based application`() {

Check warning on line 12 in src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/test/kotlin/org/hiero/gradle/test/LegacyClasspathTest.kt#L12

The function can build a classpath-based application is missing documentation.
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