Claus Ibsen created CAMEL-24843:
-----------------------------------
Summary: camel run / validate: a Groovy script importing a class
that is not on the classpath should say how to add the dependency
Key: CAMEL-24843
URL: https://issues.apache.org/jira/browse/CAMEL-24843
Project: Camel
Issue Type: Improvement
Components: camel-jbang, camel-groovy
Reporter: Claus Ibsen
An inline Groovy expression (or a .groovy file) that imports a third-party
class, as the transform/groovy example of camel-jbang-examples teaches:
{code:yaml}
- when:
expression:
groovy: |
import org.apache.commons.validator.routines.EmailValidator
EmailValidator.getInstance().isValid(body.email)
{code}
fails at runtime, per message, with
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script_259d55ee9aebf274c9826ffac9b9e983.groovy: 1: unable to resolve class
org.apache.commons.validator.routines.EmailValidator
{code}
Nothing says that the class needs a dependency and how one is added with the
Camel CLI
({{camel.jbang.dependencies=commons-validator:commons-validator:1.9.0}} in
application.properties, or {{//DEPS}} in the file). Two improvements:
* {{camel validate yaml}} and {{camel validate source}} on a .groovy file: for
each import, when the class is not on the classpath and the package is a known
third-party library (camel-kamelet-main's known dependencies, CAMEL-24809) say
the coordinates; otherwise say that the dependency must be declared and how. A
run-time wrapper of the Groovy compilation error can say the same.
* The known-third-party-libraries list has no entry for
{{org.apache.commons.validator}} (commons-validator:commons-validator); add it,
since an example teaches exactly this library.
Found in the round-2 local-model benchmark on the camel-jbang-examples ladder
(transform/groovy): the model wrote the import, got the compiler message, and
never learned that a dependency was the missing piece.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)