This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 8ccf7a9b8f2b CAMEL-27447: camel-jbang - download the JDBC driver of
debezium-mysql and debezium-db2, and add it on export (#30662)
8ccf7a9b8f2b is described below
commit 8ccf7a9b8f2ba5d511670cbcf2e2bbffe7640f1f
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 15:49:26 2026 +0100
CAMEL-27447: camel-jbang - download the JDBC driver of debezium-mysql and
debezium-db2, and add it on export (#30662)
A debezium-mysql route failed to start on the Camel CLI with
ClassNotFoundException: com.mysql.cj.jdbc.Driver. The MySQL driver is GPL
licensed, so camel-debezium-mysql declares it provided, and Debezium loads
it with Class.forName on the class loader of its connector, which does not
go through the class resolver that downloads the known third-party
libraries (as it does for a sql or jdbc route). The Debezium Db2 connector
has the same problem: its driver com.ibm.db2:jcc (IBM IPLA license) is a
provided dependency of Debezium. The Oracle, SQL Server, PostgreSQL and
MongoDB connectors depend on their driver, so it comes with the component.
The component resolver of camel-kamelet-main already resolved the pooled-jms
class for activemq through the class resolver. That is now a small table of
component name to needed class, with debezium-mysql
(com.mysql.cj.jdbc.Driver)
and debezium-db2 (com.ibm.db2.jcc.DB2Driver). Resolving the class downloads
the library from known-third-party-libraries.properties in the version Camel
manages, and the download is recorded, so camel export adds it to the
exported project too. Camel itself still does not depend on either driver.
The Db2 driver is mapped by package with a new debezium-db2-jcc-version
property in camel-parent.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/docs/debezium-db2-component.adoc | 17 +++++++
.../catalog/docs/debezium-mysql-component.adoc | 3 ++
.../src/main/docs/debezium-db2-component.adoc | 17 +++++++
.../src/main/docs/debezium-mysql-component.adoc | 3 ++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 10 ++++
.../modules/ROOT/pages/camel-jbang-running.adoc | 12 +++++
.../DependencyDownloaderComponentResolver.java | 26 ++++++++--
.../main/known-third-party-libraries.properties | 1 +
.../DependencyDownloaderComponentResolverTest.java | 55 +++++++++++++++++++++-
parent/pom.xml | 1 +
10 files changed, 141 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
index eb90d935fd87..427ed7489d58 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
@@ -66,6 +66,23 @@ for this component.
debezium-db2:name[?options]
----
+[NOTE]
+====
+The JDBC driver of Db2 is not included, as its license is not the Apache
license. Add the dependency for
+`com.ibm.db2:jcc` to your POM file:
+
+[source,xml]
+----
+<dependency>
+ <groupId>com.ibm.db2</groupId>
+ <artifactId>jcc</artifactId>
+ <version>x.x.x</version>
+</dependency>
+----
+
+The Camel CLI downloads the driver by itself when a route uses this component,
and `camel export` adds it to the
+exported project.
+====
// component options: START
include::partial$component-configure-options.adoc[]
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
index 38996494c21e..13cdcdd211b9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
@@ -76,6 +76,9 @@ Due to licensing issues, you will need to add the dependency
for `mysql-connecto
<version>8.0.15</version>
</dependency>
----
+
+The Camel CLI downloads the driver by itself when a route uses this component,
and `camel export` adds it to the
+exported project.
====
// component options: START
diff --git
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
index eb90d935fd87..427ed7489d58 100644
---
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
+++
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
@@ -66,6 +66,23 @@ for this component.
debezium-db2:name[?options]
----
+[NOTE]
+====
+The JDBC driver of Db2 is not included, as its license is not the Apache
license. Add the dependency for
+`com.ibm.db2:jcc` to your POM file:
+
+[source,xml]
+----
+<dependency>
+ <groupId>com.ibm.db2</groupId>
+ <artifactId>jcc</artifactId>
+ <version>x.x.x</version>
+</dependency>
+----
+
+The Camel CLI downloads the driver by itself when a route uses this component,
and `camel export` adds it to the
+exported project.
+====
// component options: START
include::partial$component-configure-options.adoc[]
diff --git
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
index 38996494c21e..13cdcdd211b9 100644
---
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
+++
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
@@ -76,6 +76,9 @@ Due to licensing issues, you will need to add the dependency
for `mysql-connecto
<version>8.0.15</version>
</dependency>
----
+
+The Camel CLI downloads the driver by itself when a route uses this component,
and `camel export` adds it to the
+exported project.
====
// component options: START
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 1144eda36feb..c8b3075316e7 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2481,6 +2481,16 @@ with another element type fails. SEARCH fails on a
`List` body.
REMOVE now fails when the body is not text (a `String`, bytes or a stream) or
a `Collection` of `String` IDs. Before, a
`Map` or a number body removed the ID made of its `toString()`, which usually
removed nothing.
+=== camel-jbang - camel run and camel export add the JDBC driver of
debezium-mysql and debezium-db2
+
+The MySQL JDBC driver (`com.mysql:mysql-connector-j`, GPL) and the Db2 JDBC
driver (`com.ibm.db2:jcc`, IBM
+International Program License Agreement) are not dependencies of
`camel-debezium-mysql` and `camel-debezium-db2`, so a
+route with `debezium-mysql` or `debezium-db2` failed on `camel run` with a
`ClassNotFoundException` unless the driver
+was added with `--dep`. `camel run` now downloads the driver in the version
Camel manages, and `camel export` adds it,
+with that version, to the exported project (Camel Main, Spring Boot and
Quarkus). A driver you add yourself, with
+`--dep`, `camel.jbang.dependencies` or in the project's POM, is used instead.
Remove the driver from the exported
+project if its license does not suit you.
+
=== camel-jbang - camel run uses MariaDB Connector/J 4
Camel is upgraded to MariaDB Connector/J 4.0
(`org.mariadb.jdbc:mariadb-java-client`), which is the version
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
index 6ad17c4119fb..44590d3d2434 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
@@ -435,6 +435,18 @@ headers of the `aws-s3-source` Kamelet gets
`camel-aws2-s3` before the route is
that is only looked up while running still needs the component class itself,
so probing whether
a class is present does not download a component.
+A few components need a library that is not one of their dependencies and load
its classes without
+asking Camel, so no lookup would happen. Camel CLI looks up a class of the
library when a route uses
+the component, which downloads the library in the version Camel manages, and
`camel export` adds it
+to the exported project:
+
+* `activemq` and `activemq6`: the JMS connection pool
`org.messaginghub:pooled-jms`.
+* `debezium-mysql`: the MySQL JDBC driver `com.mysql:mysql-connector-j`, which
is under the GPL.
+* `debezium-db2`: the Db2 JDBC driver `com.ibm.db2:jcc`, which is under the
IBM International
+ Program License Agreement.
+
+The other Debezium components come with the JDBC driver of their database.
+
A dependency you declare yourself, with `--dep`, `camel.jbang.dependencies`,
or in the project's
POM, is on the classpath before any lookup, so it always takes precedence. Use
that when a
mapped library is not the one you want, for example the ActiveMQ 5 client
where the mapping
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
index 9fd8e709ced8..cf46a230b323 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
@@ -18,6 +18,7 @@ package org.apache.camel.main.download;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
@@ -44,6 +45,24 @@ public final class DependencyDownloaderComponentResolver
extends DefaultComponen
"stub", "direct", "log", "seda"
};
+ /**
+ * A class that a component needs, from a library that is not a dependency
of the component, by component name. The
+ * class is resolved through the class resolver when the component is
resolved, which downloads its library from the
+ * third-party known dependencies (known-third-party-libraries.properties)
in the version Camel manages. As the
+ * download is recorded, camel export adds the library to the exported
project too.
+ * <p/>
+ * The JDBC drivers of the Debezium connectors that their license keeps
out of the component are here (CAMEL-27447):
+ * Debezium loads the driver itself with Class.forName, which does not go
through the class resolver.
+ */
+ private static final Map<String, String> NEEDED_CLASSES = Map.of(
+ // the JMS connection pool
+ "activemq", "org.messaginghub.pooled.jms.JmsPoolConnectionFactory",
+ "activemq6",
"org.messaginghub.pooled.jms.JmsPoolConnectionFactory",
+ // the MySQL JDBC driver is GPL licensed
+ "debezium-mysql", "com.mysql.cj.jdbc.Driver",
+ // the Db2 JDBC driver is under the IBM International Program
License Agreement
+ "debezium-db2", "com.ibm.db2.jcc.DB2Driver");
+
private final CamelCatalog catalog = new DefaultCamelCatalog();
private final CamelContext camelContext;
private final DependencyDownloader downloader;
@@ -117,10 +136,11 @@ public final class DependencyDownloaderComponentResolver
extends DefaultComponen
downloader.downloadDependency("org.hibernate.orm",
"hibernate-core", "${hibernate-version}");
}
}
- if ("activemq".equals(name) || "activemq6".equals(name)) {
- // need to include JMS connection-pool (trigger class loader to
download correct JAR)
+ String neededClass = NEEDED_CLASSES.get(name);
+ if (neededClass != null) {
+ // trigger the class loader to download the JAR of the class
(known-third-party-libraries.properties)
try {
-
camelContext.getClassResolver().resolveClass("org.messaginghub.pooled.jms.JmsPoolConnectionFactory");
+ camelContext.getClassResolver().resolveClass(neededClass);
} catch (Exception e) {
// ignore
}
diff --git
a/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
b/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
index 72f6b87c9276..0410bf96e4d2 100644
--- a/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
+++ b/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
@@ -33,6 +33,7 @@
# JDBC drivers, datasources and connection pools
org.postgresql = org.postgresql:postgresql:${pgjdbc-driver-version}
com.mysql.cj = com.mysql:mysql-connector-j:${debezium-mysql-connector-version}
+com.ibm.db2.jcc = com.ibm.db2:jcc:${debezium-db2-jcc-version}
org.mariadb.jdbc = org.mariadb.jdbc:mariadb-java-client:${mariadb-version}
com.microsoft.sqlserver.jdbc =
com.microsoft.sqlserver:mssql-jdbc:${mssql-jdbc-version}
oracle.jdbc = com.oracle.database.jdbc:ojdbc17:${ojdbc-version}
diff --git
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
index 3c418c39a81c..30d1ff4cd562 100644
---
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
+++
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -46,14 +47,63 @@ class DependencyDownloaderComponentResolverTest {
assertTrue(downloaded.contains("camel-http"), downloaded.toString());
}
+ @Test
+ void theDebeziumMySqlConnectorDownloadsTheMySqlDriver() throws Exception {
+ // CAMEL-27447: the MySQL driver is GPL licensed and not a dependency
of camel-debezium-mysql, and Debezium
+ // loads it with Class.forName, which does not go through the class
resolver that downloads it
+ List<String> downloaded = download("debezium-mysql");
+ assertDownloaded(downloaded, "org.apache.camel:camel-debezium-mysql");
+ assertDownloaded(downloaded, "com.mysql:mysql-connector-j");
+ }
+
+ @Test
+ void theDebeziumDb2ConnectorDownloadsTheDb2Driver() throws Exception {
+ // CAMEL-27447: the Db2 driver is a provided dependency of the
Debezium Db2 connector
+ List<String> downloaded = download("debezium-db2");
+ assertDownloaded(downloaded, "org.apache.camel:camel-debezium-db2");
+ assertDownloaded(downloaded, "com.ibm.db2:jcc");
+ }
+
+ @Test
+ void theOtherDebeziumConnectorsComeWithTheirDriver() throws Exception {
+ // the Debezium connector depends on the driver, so it is a dependency
of the component
+ for (String component : List.of("debezium-postgres",
"debezium-sqlserver", "debezium-oracle", "debezium-mongodb")) {
+ List<String> downloaded = download(component);
+ assertEquals(1, downloaded.size(), downloaded.toString());
+ assertDownloaded(downloaded, "org.apache.camel:camel-" +
component);
+ }
+ }
+
+ @Test
+ void activeMqDownloadsTheJmsConnectionPool() throws Exception {
+ List<String> downloaded = download("activemq");
+ assertDownloaded(downloaded, "org.messaginghub:pooled-jms");
+ }
+
+ /** The dependency is asked once, with a version (the third-party versions
are resolved at build time). */
+ private static void assertDownloaded(List<String> downloaded, String
groupIdArtifactId) {
+ List<String> found = downloaded.stream().filter(gav ->
gav.startsWith(groupIdArtifactId + ":")).toList();
+ assertEquals(1, found.size(), downloaded.toString());
+ String version = found.get(0).substring(groupIdArtifactId.length() +
1);
+ assertTrue(!version.isBlank() && !"null".equals(version) &&
!version.contains("${"), found.get(0));
+ }
+
/** The artifacts the resolver asks to download for the component, with
nothing on the classpath. */
private static List<String> resolve(String component) throws Exception {
+ return download(component).stream().map(gav ->
gav.split(":")[1]).toList();
+ }
+
+ /**
+ * The groupId:artifactId:version the resolver asks to download for the
component, with nothing on the classpath and
+ * the class resolver of Camel CLI, which downloads the known third-party
libraries.
+ */
+ private static List<String> download(String component) throws Exception {
List<String> downloaded = new ArrayList<>();
DependencyDownloader downloader = (DependencyDownloader)
Proxy.newProxyInstance(
DependencyDownloaderComponentResolverTest.class.getClassLoader(),
new Class<?>[] { DependencyDownloader.class }, (proxy, method,
args) -> switch (method.getName()) {
case "downloadDependency" -> {
- downloaded.add((String) args[1]);
+ downloaded.add(args[0] + ":" + args[1] + ":" +
args[2]);
yield null;
}
case "hashCode" -> System.identityHashCode(proxy);
@@ -63,6 +113,9 @@ class DependencyDownloaderComponentResolverTest {
});
try (CamelContext context = new DefaultCamelContext()) {
context.addService(downloader);
+ KnownDependenciesResolver known = new
KnownDependenciesResolver(context, null, null);
+ known.loadKnownDependencies();
+ context.setClassResolver(new
DependencyDownloaderClassResolver(context, known, false));
DependencyDownloaderComponentResolver resolver
= new DependencyDownloaderComponentResolver(context, null,
false, false);
try {
diff --git a/parent/pom.xml b/parent/pom.xml
index 6a42e616ccc6..7f7d25615587 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -157,6 +157,7 @@
<dapr-workflow-version>1.19.0</dapr-workflow-version>
<datasonnet-mapper-version>3.0.1.3</datasonnet-mapper-version>
<debezium-version>3.7.1.Final</debezium-version>
+ <debezium-db2-jcc-version>12.1.5.0</debezium-db2-jcc-version>
<debezium-mysql-connector-version>26.10.0</debezium-mysql-connector-version>
<dhis2-version>3.0.2</dhis2-version>
<directory-api-version>2.1.9</directory-api-version>