Scheduled tasks with groovy

Hello everyone

I am currently trying to deploy a script pair using the scheduled tasks module. I created a couple of script in groovy and they work correctly, but when I deploy it in CUBA PLATAFORM, I get an error loading the libraries.

Basically what I need to do is shoot a get or post to services inside my backoffice.

I enclose the script code that I am using. Thanks to everyone beforehand.

@Grab (group = ‘org.apache.httpcomponents’, module = ‘httpclient’, version = ‘4.5.2’)
@Grab (group = ‘org.postgresql’, module = ‘postgresql’, version = ‘9.4-1205-jdbc42’)
@GrabConfig (systemClassLoader = true)

import org.apache.http.client.methods. *
import org.apache.http.impl.client. *
import groovy.sql.Sql

try {

def urlDB = ‘jdbc: postgresql: // xxxxxxx’ /
def user = ‘user’
def password = ‘password’
def driver = ‘org.postgresql.Driver’
def url = ‘’
def sql = Sql.newInstance (urlDB, user, password, driver)

sql.eachRow (’’ ‘SELECT * FROM configuration WHERE key =?’ ‘’, [‘bo_url_cleanup’]) {config ->
url = config.value

sql.close ()

def post = new HttpPost (url)
def client = HttpClientBuilder.create (). build ()
def response = client.execute (post)
def bufferedReader = new BufferedReader (new InputStreamReader (response.getEntity (). getContent ()))
def jsonResponse = bufferedReader.getText ()

println (“response: \ n” + jsonResponse)
return “response: \ n” + jsonResponse
} catch (Exception e) {
println (“Exception: $ {e}”)
return “Exception: $ {e}”

Cuba returns the following error I guess they are by the libraries @Grab, but I don’t know how I should load them. Help me pleeeese…

java.lang.NoClassDefFoundError: org/apache/ivy/core/settings/IvySettings


welcome to the CUBA world :slight_smile:

I would assume @Grab does not work in a deployed scenario. It will basically to dependency management on the fly.

But the context it is running, probably there are already all dependencies that you need. E.g. postgres drivers should be there because your CUBA app is also running against it?
Also there is capabilities to execute HTTP calls via Spring e.g.

Have you tried get rid of the @Grab annotation?