Dependencies and Component Resolution

Camel K tries to resolve automatically a wide range of dependencies that are required to run your integration code.

For example, take the following integration:

from("imap://admin@myserver.com")
  .to("seda:output")

Since the integration has a endpoint starting with the "imap:" prefix, Camel K is able to automatically add the "camel-mail" component to the list of required dependencies. The seda: endpoint belongs to camel-core that is automatically added to all integrations, so Camel K will not add additional dependencies for it. This dependency resolution mechanism is transparent to the user, that will just see the integration running.

Automatic resolution is also a nice feature in dev mode, because you are allowed to add all components you need without exiting the dev loop.

Camel K won’t be able to automatically the dependencies when your routes specify dynamic URIs.

Add explicit dependencies

You can explicitly add dependency using the -d flag of the kamel run command. This is useful when you need to use dependencies that are not included in the Camel catalog or when the URI of your routes cannot be automatically discovered (see Dynamic URIs). For example:

kamel run -d mvn:com.google.guava:guava:26.0-jre -d camel-mina2 Integration.java

With that command you will add a dependency of Guava and the Camel Mina component. This feature can also be disabled if needed (although we discourage you from doing it) by disabling the dependencies trait (-t dependencies.enabled=false).

Kind of dependencies

The -d flag of the kamel run command is flexible and support multiple kind of dependencies.

Camel dependencies can be added directly using the -d flag like this:

kamel run -d camel-mina2 Integration.java

In this case, the dependency will be added with the correct version.

External dependencies can be added using the -d flag, the mvn prefix, and the maven coordinates:

kamel run -d mvn:com.google.guava:guava:26.0-jre Integration.java

Note that if your dependencies belong to a private repository, this repository needs to be defined. See Configure maven.

Jitpack dependencies can be added using the -d flag, the github prefix, and the project in the form github:user/repo/version:

kamel run -d github:apache/commons-csv/1.1 Integration.java

Dynamic URIs

Unfortunately, Camel K won’t be able to always discover all your dependencies. When you are creating an URI dynamically, then you will also need to instruct Camel K on which is the expected component to load (via -d parameter). An example is illustrated in the following code snippet:

DynamicURI.java
...
String myTopic = "purchases"
from("kafka:" + myTopic + "? ... ")
    .to(...)
...

Here the from URI is dynamically created from some variables that will be resolved at runtime. In cases like this, you will need to specify the component and the related dependency to be loaded in the Integration.