Federico Mariani created CAMEL-25528:
----------------------------------------

             Summary: camel-jbang - camel run ignores camel.jbang.dependencies 
in a properties file given on the command line, such as 
camel/application.properties
                 Key: CAMEL-25528
                 URL: https://issues.apache.org/jira/browse/CAMEL-25528
             Project: Camel
          Issue Type: Improvement
          Components: camel-jbang
    Affects Versions: 4.22.1
            Reporter: Federico Mariani


*Problem*

{{camel run}} reads {{camel.jbang.dependencies}} (and 
{{camel.jbang.dependencies.main}} / {{.spring-boot}} / {{.quarkus}}) only from 
the profile properties: {{application.properties}} (and 
{{application-<profile>.properties}}) of the current directory, or of 
{{--source-dir}}. A properties file given explicitly on the command line, or 
with {{--properties}}, is only used for property placeholders: the dependencies 
declared in it are silently ignored, with no warning.

So a project laid out with the routes and their properties in a subfolder works 
with {{camel run camel}} (the directory runs as {{--source-dir}}, so 
{{camel/application.properties}} is the profile file), but not with {{camel run 
camel/*.yaml camel/application.properties}} from the same place.

The runtime still downloads jars on demand for the classes in 
{{camel-main-known-dependencies.properties}} and the other known-dependencies 
tables (e.g. {{org.postgresql.ds.PGSimpleDataSource}}), so some setups work by 
accident and hide the problem. Beans whose class is not mapped fail with 
{{ClassNotFoundException}}, for example the Spring transaction manager and the 
Spring transaction policy of a transacted route.

We found this while evaluating AI coding agents on legacy-to-Camel migrations: 
the agents declare {{camel.jbang.dependencies}} in 
{{camel/application.properties}}, as documented, run {{camel run camel/*.yaml 
camel/application.properties}} from the project root, and get up to 27 
{{ClassNotFoundException}} per attempt before they find a workaround 
({{--dep}}).

*Reproduction*

{{camel/routes.camel.yaml}}:
{code:yaml}
- beans:
    - name: txManager
      type: org.springframework.jdbc.datasource.DataSourceTransactionManager
      properties:
        dataSource: "#bean:myDataSource"
    - name: myDataSource
      type: org.h2.jdbcx.JdbcDataSource
      properties:
        url: jdbc:h2:mem:demo
- route:
    from:
      uri: timer:tick
      parameters:
        repeatCount: 1
      steps:
        - log: "${bean:txManager}"
{code}

{{camel/application.properties}}:
{code}
camel.jbang.dependencies=camel:sql
{code}

>From the parent directory of {{camel}}:
{code}
camel run camel/routes.camel.yaml camel/application.properties
{code}

*Expected:* camel-sql (and so spring-jdbc) is on the classpath, as with {{camel 
run camel}} or {{camel run camel/routes.camel.yaml --dep=camel:sql}}.
*Actual:* {{java.lang.ClassNotFoundException: 
org.springframework.jdbc.datasource.DataSourceTransactionManager}}; 
{{camel.jbang.dependencies}} is ignored without any message.

*Proposal*

# {{camel run}} adds the dependencies ({{camel.jbang.dependencies}} and the 
variant of the runtime in use) of the local properties files given on the 
command line or with {{--properties}}, after the ones of the profile properties 
(which are not read twice) and the {{--dep}} ones. Remote files ({{github:}}, 
{{classpath:}}...) are skipped. The other {{camel.jbang.*}} keys keep being 
read from the profile properties only.
# Map the common Spring transaction classes in 
{{camel-main-known-dependencies.properties}}, so a transacted route's beans 
resolve on demand: {{DataSourceTransactionManager}}, {{JdbcTransactionManager}} 
and {{DriverManagerDataSource}} to {{camel:sql}} (spring-jdbc), 
{{PlatformTransactionManager}}, {{TransactionTemplate}} and 
{{org.apache.camel.spring.spi.SpringTransactionPolicy}} to {{camel:spring}} 
(spring-tx).
# Document where {{camel.jbang.dependencies}} is read from.

Related: CAMEL-22673 (dependencies in a non-profile {{--properties}} file not 
picked up, closed as Information Provided).




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

Reply via email to