Quarkus FaaS Maven multimodule project with #Funqy - maven

Im building a maven multimodule project.
Actualy I have to modules. In both of them I create a #Funqy function.
=== Project ===
- main
- module1
- com.example
- Function1
- module2
- com.example
- Function2
==== The Function1 ===
#ApplicationScoped
public class Function1{
#Funq
public String hello(String name) {
return "Hello " + name;
}
}
==== The Function2 ===
#ApplicationScoped
public class Function2{
#Funq
public String bye(String name) {
return "Bye" + name;
}
}
When I try to run the application I am expecting both functions to run but only the function from the first module is running. So I can call localhost:8080/hello?name=myname but I get NOT_FOUND for localhost:8080/bye?name=myname.
That is my first expirience with Funqy-Http and I am not sure what is the problem. But my intention is to create a multimodule maven project, where each module has its own functions (#Funqy).

Related

I cannot reference a Gradle custom extension using a closure

I'm writing a custom gradle plugin that uses an extension. Here's what the relevant part look like:
class Aar2Jar implements org.gradle.api.Plugin<Project> {
void apply (Project project) {
println('applying Android Jar')
def ext = project.extensions.create('jarSpec', JarSpecExtension)
if (ext.name.get() == "") {
ext.name.set(project.name)
}
and Here's what the extension looks like:
package test.android.gradle
import org.gradle.api.provider.Property
abstract class JarSpecExtension {
abstract Property<String> getName()
abstract Property<String> getVersion()
abstract Property<String> getInclude()
abstract Property<String> getExclude()
JarSpecExtension() {
name.convention("")
version.convention("1.0.0")
include.convention("*")
exclude.convention("")
}
}
And here's what my build.gradle script that uses this custom plugin looks like:
plugins {
id 'com.android.library'
id 'test.android.jar'
}
jarSpec {
name = 'myJar'
}
The problem is that doesn't work and I get the following error:
* What went wrong:
An exception occurred applying plugin request [id: 'test.android.jar']
> Failed to apply plugin 'test.android.jar'.
> No such property: extensions for class: test.android.gradle.Aar2Jar
However, if I change the build.gradle file to this:
plugins {
id 'com.android.library'
id 'test.android.jar'
}
jarSpec.name = 'myJar'
It works perfect. The question is why can I not refer to the extension using the closure style. I'm using gradle version 7.2.

How to pass #Input String in a task in buildSrc

This custom plugin exists in gradle's buildSrc/:
abstract class MyTask : DefaultTask() {
#get:Input
abstract val buildDir: Property<String>
#TaskAction
fun someTask() {
// do stuff
}
}
class DevelopmentPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.run {
register("myTask", MyTask::class.java) {
inputs.property("buildDir", project.buildDir)
println(inputs.getProperties())
}
}
}
}
and by running the task with e.g. $ ./gradlew myTask fails with:
Could not determine the dependencies of task ':myTask'.
> Cannot query the value of task ':myTask' property 'rootDir' because it has no value available.
Also the prinln outputs {buildDir=null} meaning that the inputs.property("buildDir", project.buildDir) has failed.
How to pass the project.buildDir value from the Plugin in the task?
Using project.buildDir directly from inside the task is not an acceptable answer due to Gradle's incubating build-cache functionality.
Firstly, there is a class type issue which is not visible in Gradle.
buildDir is of type File while the property is String.
So "${project.buildDir}" should be used.
Secondly, since the property is abstract val it can directly be accessed in the closure. Therefore it can be set with:
// instead of:
inputs.property("buildDir", "${project.buildDir}")
// just this:
buildDir.set("${project.buildDir}")

How to provide the value of a #Nested property of a gradle task?

The gradle doc describes the #Nested annotation for custom gradle tasks:
https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_input_output_annotations
Unfortunately, there is no complete example of this mechanism in terms of how it is used in a build.gradle file. I created a project to demonstrate a strange exception that happens whenever gradle configures the project:
https://github.com/NicolasRouquette/gradle-nested-property-test
The build.gradle has the following:
task T(type: NestedTest) {
tool = file('x')
metadata = {
a = "1"
}
}
The NestedTest custom task is in the buildSrc folder:
class NestedTest extends DefaultTask {
#InputFile
public File tool
#Nested
#Input
public Metadata metadata
#TaskAction
def run() throws IOException {
// do something...
}
}
The important bit is the #Nested property whose type is really basic:
class Mlang-groovyetadata {
String a
}
When I execute the following: ./gradlew tasks, I get this:
Build file '/opt/local/github.me/gradle-nested-property-test/build.gradle' line: 26
* What went wrong:
A problem occurred evaluating root project 'gradle-nested-property-test'.
> Cannot cast object 'build_6wy0cf8fn1e9nrlxf3vmxnl5z$_run_closure4$_closure5#2bde737' with class 'build_6wy0cf8fn1e9nrlxf3vmxnl5z$_run_closure4$_closure5' to class 'Metadata'
Can anyone explain what is happening and how to make this work?
Nicolas
Looking at the unit tests in Gradle's source code, I found that the syntax for #Nested properties requires invoking the type constructor in the build.gradle file.
That is, the following works:
task T(type: NestedTest) {
tool = file('x')
metadata = new Metadata(
a: "1"
)
}

does jenkins shared library groovy class support groovy trait

i have a shared library with a simple class that implement a simple trait,
HelloTrait.groovy :
package my.package
trait HelloTrait
{
String sayHi()
{
return "Hi!"
}
}
Test.groovy:
package my.package
class Test implements Hellotrait
{
}
jenkinsfile:
import my.package.Test
Test test = new Test();
echo test.sayHi();
but when running the pipeline jenkins throws an error
unsupported array expression

How to Change the Package of a Maven Plug-in With Testing Harness

I used this tutorial to create a very basic setup to create and test a Maven mojo. The two classes look something like this.
Mojo:
/**
* #goal touch
* #phase process-sources
*/
public class MyMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
// stuff
}
}
Test:
public class MyMojoTest {
#Rule
public MojoRule rule = new MojoRule();
#Test
public void testSomething() throws Exception {
File pom = new File("src/test/resources/pom.xml");
MyMojo myMojo = (MyMojo) rule.lookupMojo("touch", pom);
Assert.assertNotNull(myMojo);
myMojo.execute();
}
}
It works so far. Then I moved it to my own project, to see why my tests wouldn't work. It still worked until I moved the classes into another package.
The default is org.apache.maven.plugin.my and I'm not sure if that is somehow forced for all Maven plug-ins or taken from some weird property I can't figure out.
Properties that don't contribute to this package are:
pom's artifact ID
pom's group ID
pom's version
The error message is:
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.apache.maven.plugin.Mojo
roleHint: org.acme:maven-my-plugin:1.0.0-SNAPSHOT:touch
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:264)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:240)
at org.codehaus.plexus.PlexusTestCase.lookup(PlexusTestCase.java:205)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:389)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:334)
at org.apache.maven.plugin.testing.MojoRule.lookupMojo(MojoRule.java:164)
at org.apache.maven.plugin.my.MyMojoTest.testSomething(MyMojoTest.java:22)
So how do I change the package? org.apache.maven.plugin.my sounds really tutorially.
I found a bunch of stupid mistakes why my mojos (including the above one) won't work, like:
Maven mojos don't get compiled automatically like Java files, you need to start Maven manually (or use somthing like Maven -> Update Project in your IDE)
I imported org.junit.jupiter.api.Test instead of org.junit.Test, so the MojoRule was not initialized correctly

Resources