GoogleCloudPlatform / buildpacks

Builders and buildpacks designed to run on Google Cloud's container platforms
Apache License 2.0
953 stars 145 forks source link

google.java.functions-framework builder does not support Gradle Kotlin DSL build.gradle.kts #406

Open StephenWithPH opened 2 months ago

StephenWithPH commented 2 months ago

Describe the bug Having created a project via gradle init (Gradle 8.7) and chosen the Kotlin DSL, the following error ultimately surfaces:

[builder] Done "./gradlew clean assemble -x test --build-cache --quiet" (1m6.044632762s)
[builder] === Java - Functions Framework (google.java.functions-framework@1.1.0) ===
[builder] --------------------------------------------------------------------------------
[builder] failed to build: (error ID: 0f436744):
[builder] function has neither pom.xml nor already-built jar file; directory has these entries: .git, .gitattributes, .github, .gitignore, .gradle, README.md, build, build.gradle.kts, gradle, gradlew, gradlew.bat, settings.gradle.kts, src

Creating a project via gradle init and choosing the Groovy DSL leads to a buildable project.

Note that it seems necessary to "flatten" the project out of its default, multi-module shape. I don't believe this is relevant to the above, but will be necessary to avoid masking the error above.


Additional context How are you using GCP buildpacks?


Did this used to work? (Yes/No) Unknown

What language is your project primarily written in? (Python/Java/Node.js/Go/etc.) Kotlin

Steps To Reproduce Steps to reproduce the behavior:

  1. gradle init per above, choosing Application, Kotlin, Java 21, Single application project, Kotlin DSL, no new apis/behaviors
  2. "flatten" the generated code by moving src up out of app and removing the include from settings.gradle. Note that this is to avoid masking the error.
  3. pack build \ --builder gcr.io/buildpacks/builder:latest \ --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \ --env GOOGLE_FUNCTION_TARGET=org.example.App \ --env GOOGLE_RUNTIME_VERSION=21 \ my-first-function

Expected behavior It builds.

Actual behavior It gives the error above:

function has neither pom.xml nor already-built jar file


The error appears to come from:

https://github.com/GoogleCloudPlatform/buildpacks/blob/5bbd4eb223214116d2257d134c98067fc8ba1b69/cmd/java/functions_framework/main.go#L146

Earlier in that func classpath, the Gradle check only checks for (Groovy DSL syntax) build.gradle, neglecting to check for build.gradle.kts:

https://github.com/GoogleCloudPlatform/buildpacks/blob/5bbd4eb223214116d2257d134c98067fc8ba1b69/cmd/java/functions_framework/main.go#L119


Note that a fix to support build.gradle.kts went into the google.java builder in https://github.com/GoogleCloudPlatform/buildpacks/commit/37ecf33ead9b4feb296fd15b25a0d1f16825cc30 , but that did not touch the functions-framework builder.

SandeepTuniki commented 1 month ago

Hi @StephenWithPH, thank you for spotting this issue, and for providing the detailed analysis.

I can reproduce this issue on my end. I'm working on a fix for this.

In the meantime, could you share the test app that you created? If possible, could you share it as a Github repo? I am specifically interested in the build.gradle.kts & settings.gradle files in your app.

StephenWithPH commented 1 month ago

@SandeepTuniki ... that's great to hear! Thank you for picking this one up.

You can see a repro (same code works with Groovy DSL and fails with Kotlin DSL) at https://github.com/StephenWithPH/buildpack-kotlin-dsl-repro .

SandeepTuniki commented 1 month ago

Hi @StephenWithPH, thanks for the extra details! I dug into this and found that the fix is a bit more involved than just adding a check to the build.gradle.kts file. This is actually a feature we haven't fully implemented yet—Cloud Functions doesn't currently support Kotlin DSL.

We've got this on our radar for future updates, but for now, I'd recommend using either Maven or Gradle with Groovy DSL. We've got some helpful guides on that here: https://cloud.google.com/functions/docs/create-deploy-http-java.

StephenWithPH commented 1 month ago

@SandeepTuniki ... the non-functions-framework builder for Java does handle Kotlin DSL. See https://github.com/GoogleCloudPlatform/buildpacks/issues/26 and https://github.com/GoogleCloudPlatform/buildpacks/commit/37ecf33ead9b4feb296fd15b25a0d1f16825cc30 .

Possible to crib from that in the functions-framework Java builder?

SandeepTuniki commented 1 month ago

@StephenWithPH Yes, I went through that issue and PR already while investigating. We found that changes for Functions are not as straightforward as the earlier ones. This feature is on our roadmap, but I can't provide a specific timeline right now due to other pressing priorities. Rest assured, I'll share updates as soon as we have a clearer picture.