spring-cloud-function
spring-cloud-function copied to clipboard
The Background function with GCP adapter using gradle instead of maven
The sample functions all have examples using Maven but not gradle. I tried to convert the pom.xml into a build.gradle file but was not able to achieve the same result. Could you please help with it?
Can you share how far you got and what was the blocker? cc/ @dzou
We are having the same issue. There is no documentation on how to use Gradle with spring-cloud-functions for GCP. Is there already Gradle support for GCP or is support planned to come in the future?
The spring-cloud-function neither supports Maven nor Gradle nor any other dependency management system. . .
I mean this is the wrong way of looking at it. We simply use Maven as dependency management mechanisms of choice. Nothing should stop an expert of a particular dependency management system to configure any maven project to that system, so there is really no answer to support planned to come in the future
Hi! Is there an update on this. We would like to use Spring Cloud GCP adapter using Gradle.
Sorry for the delay, I'll take a look and update the corresponding docs. My initial guess is we need to change the JAR Layout via the gradle property to do this.
How do I config spring cloud in Gradle. I am really stuck on this
Sorry, I don't think it is possible to use it with Gradle right now due to this: https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/445#issuecomment-823578792
For people going round in circles on this, here's my working version:
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'maven-publish'
id 'org.springframework.boot.experimental.thin-launcher' version '1.0.30.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2022.0.3")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-function-adapter-gcp'
implementation 'org.springframework.cloud:spring-cloud-function-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'io.cloudevents:cloudevents-spring:2.5.0'
implementation 'io.cloudevents:cloudevents-http-basic:2.5.0'
implementation 'io.cloudevents:cloudevents-json-jackson:2.5.0'
implementation 'com.google.cloud:google-cloudevent-types:0.10.0'
implementation 'org.springframework.cloud:spring-cloud-starter-function-web'
implementation 'org.springframework.cloud:spring-cloud-function-deployer'
implementation 'org.springframework.boot:spring-boot-loader-tools'
implementation 'org.springframework.boot:spring-boot-loader'
implementation 'com.google.cloud.functions:functions-framework-api:1.1.0'
implementation 'com.google.cloud.functions.invoker:java-function-invoker:1.3.0'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
import com.github.jengelman.gradle.plugins.shadow.transformers.*
shadowJar {
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
append 'META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports'
append 'META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports'
transform(PropertiesFileTransformer) {
paths = ["META-INF/spring.factories"]
mergeStrategy = "append"
}
}
jar{
manifest {
attributes 'Main-Class': 'org.springframework.cloud.function.adapter.gcp.GcfJarLauncher'
attributes 'Start-Class': 'com.example.functions.StorageFunctionApplication'
}
}
task deploy(dependsOn: shadowJar, type: Exec){
doFirst {
file("$buildDir/libs/cloud-storage-function-trigger-0.0.1-SNAPSHOT.jar").delete()
}
workingDir "$buildDir/libs"
commandLine 'gcloud', 'functions', 'deploy', 'cloud-storage-upload-function', '--gen2',
'--region=europe-west1',
'--entry-point=org.springframework.cloud.function.adapter.gcp.GcfJarLauncher',
'--runtime=java17',
'--trigger-event-filters', 'type=google.cloud.storage.object.v1.finalized',
'--trigger-event-filters', 'bucket=yourbucket',
'--memory', '1024M', '--timeout', '540'
}
Closing it given provided solution