davsclaus opened a new pull request, #27283: URL: https://github.com/apache/camel/pull/27283
[CAMEL-25239](https://issues.apache.org/jira/browse/CAMEL-25239). Supersedes #27206: thanks @smongiar for reporting this and for the several rounds there. ## Problem A Java or Groovy source that imports a class of a Camel component, other than the component class itself, does not compile in `camel run` or `camel export`. For example, this route imports the header constants of the component used by the `aws-s3-source` Kamelet: ```java import org.apache.camel.component.aws2.s3.AWS2S3Constants; public class RouteB extends org.apache.camel.builder.RouteBuilder { @Override public void configure() { from("kamelet:aws-s3-source?bucketNameOrArn=mybucket®ion=eu-west-1&accessKey=x&secretKey=y") .log("${header." + AWS2S3Constants.KEY + "}"); } } ``` On `main`: `package org.apache.camel.component.aws2.s3 does not exist`. `camel export` fails, and with `--ignore-loading-error` it reports success but writes a pom without the Kamelet's dependencies (no `camel-aws2-s3`). The same happens when the Kamelet is used from a YAML route and a Java bean next to it imports the class. The known dependencies map each component by its component class only (`...aws2.s3.AWS2S3Component=camel:aws2-s3`). The import doesn't resolve, so the source fails to compile before the Kamelet that would bring the component is loaded. ## Fix - `KnownDependenciesResolver` also maps each component by its **package**. It skips packages shared by different dependencies (none today) and base packages such as `org.apache.camel`, which huaweicloud's `FunctionGraphComponent` sits in and which would otherwise match every Camel class. - **Imports only:** the new `mavenGavForImport` is used by `JavaKnownImportsDownloader` alone. `mavenGavForClass`, which the class resolver uses for classes looked up while running, is unchanged. A first version put the packages in the shared table, and a run then recorded `camel-file` in the export settings because of a class probe. Probing whether a class is present must not download a component. - The user manual section *how a class becomes a dependency* describes it. When the import resolves, the source compiles and the Kamelet loads, so its `spec.dependencies` are recorded as before. An import of a library that is neither known nor a component is still declared with `--dep`, as today. ## Tests - `KnownDependenciesResolverTest#anImportResolvesAnyClassOfAComponent`. It fails on `main` (`AWS2S3Constants ==> expected: not <null>`) and checks: - sibling packages (`aws2.s3` / `aws2.s3vectors`); - a sub-package of another component (`file.remote` → `camel-ftp`); - base packages are not claimed; - `mavenGavForClass` is unchanged. - The `camel-kamelet-main` tests pass (46). - `camel export` from the CLI built from this branch: | Project | `main` | this PR | |---|---|---| | Java route importing `AWS2S3Constants`, using `kamelet:aws-s3-source` | exit 1, compile error | success: `camel-aws2-s3`, `camel-kamelet`, `camel-kamelets` (Main); `camel-aws2-s3-starter` (Spring Boot); `camel-quarkus-aws2-s3` (Quarkus) | | YAML route using `kamelet:aws-s3-source`, plus a Java bean importing `AWS2S3Constants` | exit 1, compile error | success, with `camel-aws2-s3` | | YAML route alone | success | unchanged | `camel run` of the Java route now compiles. It then stops at the S3 connection, as expected with fake credentials. 4.23 only, no backport. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
