[ 
https://issues.apache.org/jira/browse/CAMEL-25239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18121962#comment-18121962
 ] 

Claus Ibsen commented on CAMEL-25239:
-------------------------------------

Reproduced on main (4.23.0-SNAPSHOT, camel export --runtime=camel-main, fresh 
run data).

*Route A:* a kamelet, plus an import that nobody provides
{code:java}
import com.acme.NotThere;

public class RouteA extends org.apache.camel.builder.RouteBuilder {
    @Override
    public void configure() {
        from("kamelet:timer-source?message=Hello")
            .to("kamelet:json-deserialize-action")
            .log("${body}");
    }
}
{code}

*Route B:* the route imports a class that only the kamelet's dependency 
provides (the circular case)
{code: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&region=eu-west-1&accessKey=x&secretKey=y")
            .log("${header." + AWS2S3Constants.KEY + "}");
    }
}
{code}

||Route||camel export||camel export --ignore-loading-error||
|A|exit 1, no pom|"Project export successful!" but the pom has no camel-jackson 
(nor camel-kamelet / camel-kamelets)|
|B|exit 1: package org.apache.camel.component.aws2.s3 does not 
exist|"successful" but no camel-aws2-s3|

Note: a Jackson import alone can't reproduce this, because camel-kamelet-main 
ships camel-jackson, so jackson-annotations/databind are always on the 
classpath.

Cause: export only learns a kamelet's dependencies when the silent run loads 
the kamelet (DependencyDownloaderKamelet writes the kamelet= and dependency= 
lines), and compiling the Java route comes first. The known-imports 
pre-processor (JavaKnownImportsDownloader) maps third-party packages and exact 
bean classes, but not Camel component packages such as 
org.apache.camel.component.aws2.s3.

Possible fix: before the silent run, export scans the sources for 
kamelet:<name> references and, for each official kamelet, adds its 
spec.dependencies from the kamelets catalog (KameletCatalogHelper) to the pom 
and downloads them before compiling. Separately, 
org.apache.camel.component.<pkg> imports could be mapped to their component 
artifact through the catalog, which also fixes camel run.

_Claude Code on behalf of davsclaus_

> camel export: kamelet spec.dependencies missing from pom.xml when Java route 
> builder fails to compile during silent run
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25239
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25239
>             Project: Camel
>          Issue Type: Bug
>            Reporter: Salvatore Mongiardo
>            Priority: Major
>
> When {{camel export}} is used with an integration that combines a Java route 
> builder and a kamelet (e.g. {{json-deserialize-action}}), the exported 
> {{pom.xml}} can be missing the kamelet's declared {{spec.dependencies}} (e.g. 
> {{camel:jackson}}).
> *Root cause:*
> {{camel export}} captures kamelet-declared dependencies through a download 
> listener that fires during a silent run. The chain is:
> # Java route builder compiles
> # Kamelet endpoint resolves
> # Kamelet template loads
> # {{DependencyDownloaderKamelet}} fires
> # Listener writes {{dependency=}} to the settings file
> If the Java route builder imports a class (e.g. {{ObjectMapper}}, 
> {{@JsonProperty}}) whose JAR is not yet on the classpath, compilation fails 
> before the kamelet is reached. Neither the {{kamelet=}} nor the 
> {{dependency=}} lines are written to the settings file, so 
> {{spec.dependencies}} are absent from the exported {{pom.xml}}.
> This is a circular bootstrap problem: the missing dependency (e.g. 
> {{jackson-databind}}) is the one the kamelet would have provided, but the 
> kamelet never loads because the route builder that uses it cannot compile 
> first.
> *Impact:*
> - Exported projects fail to build / run out of the box.
> - Affects any integration where a Java route builder has direct imports of 
> classes provided by a kamelet dependency, and the export's silent run fails 
> at compilation rather than at kamelet resolution.
> *Expected behaviour:*
> {{camel export}} should include all {{spec.dependencies}} declared by every 
> kamelet referenced in the integration in the exported {{pom.xml}}, regardless 
> of whether the silent-run download chain completes successfully.
> *Related PR:* https://github.com/apache/camel/pull/27206



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to