diff --git a/CHANGELOG.md b/CHANGELOG.md index a844ac0..5c53b63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Version 0.3.3 +* Fix 'generateProto' caching issue * JPMS - add patching rule: org.apache.logging.log4j:log4j-api (for compile time checks) * JPMS - add patching rule: org.apache.logging.log4j:log4j-api (for compile time checks) diff --git a/src/main/kotlin/org.hiero.gradle.feature.protobuf.gradle.kts b/src/main/kotlin/org.hiero.gradle.feature.protobuf.gradle.kts index cb5f594..e7723f4 100644 --- a/src/main/kotlin/org.hiero.gradle.feature.protobuf.gradle.kts +++ b/src/main/kotlin/org.hiero.gradle.feature.protobuf.gradle.kts @@ -11,7 +11,12 @@ protobuf { // Add GRPC plugin as we need to generate GRPC services plugins { register("grpc") { artifact = "io.grpc:protoc-gen-grpc-java" } } generateProtoTasks { - all().configureEach { plugins.register("grpc") { option("@generated=omit") } } + all().configureEach { + plugins.register("grpc") { option("@generated=omit") } + // Track all tools as input to react if version changes for the tools + inputs.files(configurations["protobufToolsLocator_protoc"]) + inputs.files(configurations["protobufToolsLocator_grpc"]) + } } } diff --git a/src/test/kotlin/org/hiero/gradle/test/ProtobufTest.kt b/src/test/kotlin/org/hiero/gradle/test/ProtobufTest.kt new file mode 100644 index 0000000..d403b08 --- /dev/null +++ b/src/test/kotlin/org/hiero/gradle/test/ProtobufTest.kt @@ -0,0 +1,85 @@ +// 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 ProtobufTest { + + @Test + fun `task re-runs if protobuf plugin version changes`() { + val testProto = + """ + syntax = "proto3"; + package org.hiero.product.module.a; + message Test { + bytes test_id = 1; + } + """ + .trimIndent() + val moduleInfo = + """ + module org.hiero.product.module.a { + requires com.google.protobuf; + } + """ + .trimIndent() + val aggregation = + """ + plugins { + id("java") + id("org.hiero.gradle.base.lifecycle") + } + dependencies { implementation(project(":module-a")) } + """ + .trimIndent() + + val push = GradleProject().withMinimalStructure() + val pull = GradleProject().withMinimalStructure() + push.aggregationBuildFile(aggregation) + pull.aggregationBuildFile(aggregation) + push.settingsFile.appendText( + """buildCache.local.directory = File("${push.file("build-cache").absolutePath}")""" + ) + pull.settingsFile.appendText( + """buildCache.local.directory = File("${push.file("build-cache").absolutePath}")""" + ) + push.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.protobuf") }""") + pull.moduleBuildFile("""plugins { id("org.hiero.gradle.feature.protobuf") }""") + + push.moduleInfoFile(moduleInfo) + pull.moduleInfoFile(moduleInfo) + + push.file("product/module-a/src/main/proto/test.proto", testProto) + pull.file("product/module-a/src/main/proto/test.proto", testProto) + + push.dependencyVersionsFile(dependencyVersions("4.29.0")) + pull.dependencyVersionsFile(dependencyVersions("4.29.3")) + + val pushResult = push.run("assemble --build-cache") + val pullResult = pull.run("assemble --build-cache") + + // make sure second run is not FROM-CACHE + assertThat(pushResult.task(":module-a:generateProto")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pushResult.task(":module-a:compileJava")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:generateProto")?.outcome) + .isEqualTo(TaskOutcome.SUCCESS) + assertThat(pullResult.task(":module-a:compileJava")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } + + private fun dependencyVersions(protocVersion: String) = + """ + plugins { + id("org.hiero.gradle.base.lifecycle") + id("org.hiero.gradle.base.jpms-modules") + } + dependencies.constraints { + api("com.google.protobuf:protobuf-java:4.29.0") + api("com.google.protobuf:protoc:$protocVersion") + api("io.grpc:protoc-gen-grpc-java:1.69.0") + }""" + .trimIndent() +}