Handle exceptions in micronaut scheduled tasks

By default micronaut simply logs any exceptions that are thrown during scheduled tasks. To change this behaviour you simply have to override the bean DefaultTaskExceptionHandler, the default implementation of TaskExceptionHandler with your own implementation: @Singleton @Replaces(DefaultTaskExceptionHandler.class) @Slf4j class HelloWorldTaskExceptionHandler implements TaskExceptionHandler<Object, Throwable> { //override handle method here } @Replaces lets a bean specify that it replaces another bean. All that is left is to implement the handle method which takes the offending bean and the exception that was thrown as arguments.

Workaround for using the grails-schwartz-plugin in Grails 4

Version 1.0.1 of the grails-schwartz-plugin will not work with a grails 4 application as I recently found whilst trying to upgrade an app. You will get the following compilation error: CONFIGURE SUCCESSFUL in 1s Error | Failed to compile create-job.groovy: startup failed: create-job.groovy: 23: unable to resolve class grails.transaction.Transactional @ line 23, column 1. import grails.transaction.Transactional ^ 1 error (Use --stacktrace to see the full trace) Error | Command \[run-app\] error: null (Use --stacktrace to see the full trace) Process finished with exit code 1 The create-job.

Triggering a schwartz job to run immediately in grails

The grails schwartz plugin comes with a utility service, the QuartzService, which you can use to trigger a job immediately. For example, if you want to run a job on application startup, you can just call the services' triggerJob method from the init closure in Bootstrap.groovy package schwartz.grails.plugin class BootStrap { def quartzService def helloWorldJobService def init = { servletContext -> quartzService.triggerJob(helloWorldJobService.jobKey) } def destroy = { } } The triggerJob method takes a JobKey as a parameter.

Wiring up Spring Boot DevTools

The spring-boot-dev-tools module allows you to automatically restart your application whenever you make changes. It works by detecting changes to files on the classpath. To add devtools to a project just add the dependency to your build.gradle as shown below: configurations { developmentOnly runtimeClasspath { extendsFrom developmentOnly } } dependencies { developmentOnly("org.springframework.boot:spring-boot-devtools") } If you are using Intellij IDE you can trigger a restart by building the project. When working with an IDE that continually compiles changes you can use a trigger file and restarts will only occur when that file changes.

The grails database migration plugin

Grails has a comprehensive guide on how to use the database-migration plugin for your greenfield Grails projects. The guide however does not explain clearly how to go about this with an existing app. This blog post details how to setup it up in that scenario. The first thing is to set your datasource dbCreate property to none in the application.yml: dataSource: dbCreate: none And install the plugin as mentioned in the guide.

Adding a JAR to a Grails project

When you find yourself working with an old Grails 2 project and you need to experiment with changes to one of its the dependencies without having to publish a snapshot version to an artifact repo, you can always drop the .jar into the lib folder and you are good to go. If you do not have a .pom file associated with the jar, attempting to use the local maven repo (.