Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it Possbile to run Groovy class together with java classes using Spring boot

I am trying to run my spring-boot app (using gradle and java) together with groovy classes.

So I added controller (as shown in the examples)

the controller is under src/main/groovy

@RestController
class ThisWillActuallyRun {

    @RequestMapping("/")
    String home() {
        "Hello World!"
    }

}

I also have my java classes under

src/main/java

Iam running spring boot using java -jar (or gradle in dev mode: bootRun)

Code is compiled but the groovy controller isnt loaded.

I miss some concept here about running groovy and java classes side-by-side on the same jar?

Thanks.

like image 842
rayman Avatar asked Dec 29 '25 02:12

rayman


1 Answers

I think you forgot to apply the groovy gradle plugin. I have replicated your simptoms by creating a spring boot project with both java and groovy classes, and only applying the java plugin. To be able to include groovy classes in your application, replace

apply plugin: "java"

with

apply plugin: "groovy"

The groovy plugin subclasses the java plugin, so you will still able to compile java classes.

If that is not the case, you will have to provide more information, like the gradle build script. If you are using gradle.

like image 78
Luis Muñiz Avatar answered Dec 30 '25 16:12

Luis Muñiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!