Skip to content

Fix camel export to auto-detect kamelets version from classpath#23781

Merged
davsclaus merged 1 commit into
apache:mainfrom
smongiar:fix/export-kamelets-version
Jun 5, 2026
Merged

Fix camel export to auto-detect kamelets version from classpath#23781
davsclaus merged 1 commit into
apache:mainfrom
smongiar:fix/export-kamelets-version

Conversation

@smongiar
Copy link
Copy Markdown
Contributor

@smongiar smongiar commented Jun 5, 2026

Summary

  • The --kamelets-version option in camel export was hardcoded to a compile-time default from parent/pom.xml (RuntimeType.KAMELETS_VERSION)
  • VersionHelper.extractKameletsVersion() can detect the actual kamelets jar version from the classpath, but the null-check at resolveDependencies() never triggers because the field is always pre-initialized
  • Remove the compile-time default so extractKameletsVersion() runs at runtime, detecting the actual version from the classpath and falling back to the compiled-in default only when no kamelets jar is found
  • Add the same null-check in runSilently() which runs before resolveDependencies()

Problem

When running camel export --runtime=spring-boot without explicit --kamelets-version, the generated pom.xml always uses the version compiled into RuntimeType.KAMELETS_VERSION. If the actual camel-kamelets jar on the classpath has a different version (e.g. in downstream/productized builds), the exported project gets the wrong kamelets dependency.

Reproducer

# Install a camel CLI with kamelets 4.18.x on the classpath
# Then export without --kamelets-version:
camel export --runtime=spring-boot --gav=com.example:test:1.0.0 --dir=./app MyRoute.java

# Before fix: pom.xml has <version>4.17.0</version> for camel-kamelets (compiled-in default)
# After fix: pom.xml has <version>4.18.x</version> (detected from classpath)

@Croway
Copy link
Copy Markdown
Contributor

Croway commented Jun 5, 2026

After these changes, is RuntimeType.KAMELETS_VERSION needed? I think so, I found it in CatalogKamelet and CatalogDoc can you investigate if these classes need to be updated as well?

@smongiar smongiar force-pushed the fix/export-kamelets-version branch from 5cf111e to b6cf1a6 Compare June 5, 2026 09:41
@smongiar
Copy link
Copy Markdown
Contributor Author

smongiar commented Jun 5, 2026

After these changes, is RuntimeType.KAMELETS_VERSION needed? I think so, I found it in CatalogKamelet and CatalogDoc can you investigate if these classes need to be updated as well?

RuntimeType.KAMELETS_VERSION is still needed, it's used by VersionHelper.extractKameletsVersion() when classpath detection fails. But I found another issue: defaultValue = RuntimeType.KAMELETS_VERSION eagerly set the field, making the classpath detection code path dead.

So, I updated the fix removing the defaultValue and field initializer, adding a null check that calls VersionHelper.extractKameletsVersion() which tries classpath first, then falls back to RuntimeType.KAMELETS_VERSION

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions github-actions Bot added the dsl label Jun 5, 2026
Copy link
Copy Markdown
Contributor

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regen required.

@smongiar smongiar force-pushed the fix/export-kamelets-version branch from b6cf1a6 to ab50f1e Compare June 5, 2026 12:18
@github-actions github-actions Bot added the docs label Jun 5, 2026
Copy link
Copy Markdown
Contributor

@davsclaus davsclaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-scoped fix. The compile-time default for kameletsVersion masked the runtime classpath detection, causing exported projects to always use the compiled-in version rather than the actual kamelets jar version. The fix consistently removes the pre-initialization across all 4 commands (ExportBaseCommand, CatalogKamelet, CatalogDoc, KameletTools) and lets VersionHelper.extractKameletsVersion() detect the real version at runtime. Documentation updated across 7 command reference pages.

This review does not replace specialized AI review tools (CodeRabbit, Sourcery) or static analysis (SonarCloud).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@davsclaus
Copy link
Copy Markdown
Contributor

There are uncommitted changes
HEAD detached at pull/23781/merge
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json

@smongiar smongiar force-pushed the fix/export-kamelets-version branch from ab50f1e to 1f24360 Compare June 5, 2026 15:46
The --kamelets-version option was hardcoded to a compile-time default
from parent/pom.xml in ExportBaseCommand, CatalogKamelet, CatalogDoc,
and KameletTools. When the actual kamelets jar on the classpath has a
different version (e.g. in productized builds), wrong version is used.

Remove the compile-time defaults and let VersionHelper.extractKameletsVersion()
detect the actual version from the classpath at runtime, falling back to the
compiled-in default only when no kamelets jar is found.
@smongiar smongiar force-pushed the fix/export-kamelets-version branch from 1f24360 to 7863ccb Compare June 5, 2026 16:13
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🧪 CI tested the following changed modules:

  • docs
  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-mcp

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 1 test(s) disabled on GitHub Actions
  • dsl/camel-jbang/camel-jbang-mcp: 1 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (6 modules)
  • Camel :: JBang :: Core
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher :: Container

⚙️ View full build and test results

@davsclaus davsclaus merged commit a2a044f into apache:main Jun 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants