Skip to content

feat(services): add native karaf.url service (mvn: and wrap:) and use it in karaf-light - #2333

Merged
jbonofre merged 17 commits into
apache:mainfrom
jbonofre:gh-2332
Nov 20, 2026
Merged

jbonofre merged 17 commits into
apache:mainfrom
jbonofre:gh-2332

Conversation

@jbonofre

@jbonofre jbonofre commented Mar 14, 2026 •

Copy link
Copy Markdown
Member

Part of #2212, closes #2332.

Add a native Karaf URL service as an alternative to Pax URL, and use it in the apache-karaf-light distribution.

Rebased on #2928: the Karaf URL service is now a provider of the Karaf Maven resolver SPI (org.apache.karaf.features.spi), so this PR no longer changes profile or tooling.

Karaf URL service (services/url)

  • mvn: protocol handler, resolving artifacts from the default (local, file-based) repositories, the local repository and remote repositories, without Aether. Configuration PID: org.apache.karaf.url.mvn (property names compatible with org.ops4j.pax.url.mvn).
  • Repositories use the Pax URL syntax: only the known @ options are removed, so paths and URLs containing @ (/var/jenkins/workspace/job@2, https://user:password@host/...) work. @snapshots and @noreleases apply to the remote repositories, file: remote repositories are read in place, and the repository of mvn:repository_url!groupId/artifactId/... URLs is used. An invalid repository is ignored with a warning. The @update=, @snapshotsUpdate=, @checksum=, @releasesChecksum= and @snapshotsChecksum= options of the repositories apply when the global policies are not set, as in Pax URL.
  • Remote snapshots are resolved from the maven-metadata.xml files of the repositories (Maven 3 and Maven 2 metadata), using the newest version. As in Maven, the metadata of each repository is cached in the local repository and checked again according to the update policy (daily by default). The local copy is kept when it is not older, or when the repositories can't be reached: its version is the one of its maven-metadata-local.xml (mvn install), or the one it was downloaded with, not its modification time. Without metadata in the repositories, a snapshot is only downloaded when the local repository doesn't have it.
  • Maven settings (settings, else ~/.m2/settings.xml, ${maven.home}/conf/settings.xml, ${M2_HOME}/conf/settings.xml): local repository, repositories of the active profiles (used when repositories is not set, appended when it starts with +), server credentials (by repository id), mirrors and proxies (as in Maven, the http proxy is also used for the https repositories when there is no https one).
  • Downloads go to their own temporary file, moved atomically. Checksums are verified with the same connection settings as the artifact, and the fail policy also rejects a download without a checksum. The repository ids are not used as paths in the metadata cache file names. Only the errors which may not happen again are retried, with an increasing delay, and the resolution error gives the error of each repository. Artifact paths leading outside the repositories are rejected.
  • Without configuration, the service uses the default repositories of the instance and the remote repositories of etc/org.apache.karaf.url.mvn.cfg.
  • Implements the Karaf Maven resolver SPI: registers a MavenResolverFactory, used by the features service with the org.apache.karaf.url.mvn configuration, and a ready to use MavenResolver, used by feature:export-bundles. The factory is also declared for ServiceLoader, so it can be used outside the OSGi framework. A failed resolution is not retried by the features service, as the downloads from the remote repositories are already retried (connection.retryCount). The bundle doesn't export any package.
  • wrap: protocol handler, equivalent to pax-url-wrap: same syntax (wrap:jar-url[,instructions-url][$instructions]), overwrite modes (keep, merge, full) and defaults. The manifest is generated with bnd (the build bnd.version, 7.5.0), embedded privately in the bundle (only the used packages), so all bnd instructions are supported. The bundle is about 2.5 MB because of bnd.
  • Supports the @multi repositories (KAR repositories), declares the URL handler capabilities, and waits for the ConfigAdmin configuration when org.apache.karaf.url.mvn.requireConfigAdminConfig is set. Until then, it provides neither the URL handlers nor the Maven resolver, so the features service uses the system repository.

karaf-light distribution

  • New url feature in the standard features (Karaf URL service at start level 5 with its etc/org.apache.karaf.url.mvn.cfg), used as startup feature by karaf-light.
  • karaf-light blacklists the pax-url-aether and pax-url-wrap bundles, and the org.apache.karaf.maven.resolver.paxurl provider of the framework-light feature (the wrap feature stays as marker for the wrap deployer and the wrap prerequisites). The unused Pax URL files are removed from the assembly.
  • Child instances get the Karaf URL service configuration (and not the Pax URL one), and the features processing file of the root instance with its versions.properties.
  • The Maven resolver section of the manual describes the Karaf URL service provider.

Changes for all distributions

  • Features service: uses the MavenResolverFactory with the highest service.ranking (the first registered one for the same ranking), and falls back to the best remaining one when it is unregistered. Installing the url feature in the standard distribution therefore doesn't replace Pax URL.
  • MavenDownloadTask resolves a failed artifact again without the snapshot timestamp only when its URL has one.
  • bundle:watch uses the local repository of the org.apache.karaf.url.mvn configuration when there is no Pax URL configuration, resolves a relative one in the Karaf home directory as the Karaf URL service does, and no longer breaks local repository paths containing @.

The default distribution still uses Pax URL, through org.apache.karaf.maven.resolver.paxurl.

Testing

  • Unit tests for the handlers, the resolver (repository parsing, credentials, checksums, retries, snapshots and update policies, repository policies, mirrors, server credentials and proxies from the settings, with a local HTTP repository), the configuration, the settings, the snapshot metadata, the SPI factory (with ServiceLoader and without BundleContext), the features service factory selection, bundle:watch and the instance alignment.
  • Full build, and unit tests of services/url, features/core, bundle/core and instance.
  • After the rebase on Add lightweight karaf-logging service and use it in apache-karaf-light #2949, booted karaf-light unpacked under a job@2 directory: only the Karaf URL and logging services (no Pax URL or Pax Logging bundle), wrap:mvn: install with instructions, path traversal rejected, child instance create/start. Since Add lightweight karaf-logging service and use it in apache-karaf-light #2949, feature:install karaf-web fails on karaf-light (org.apache.juli.logging is only exported by pax-logging-api), unrelated to this PR.
  • Booted karaf-light with a snapshot repository served over HTTP: the snapshot is installed, then a newer deployment, versioned before the download of the local copy, is picked by bundle:update, and a new bundle:update doesn't download it again.
  • Before the rebase on Add lightweight karaf-logging service and use it in apache-karaf-light #2949, booted karaf-light with an empty local repository and no network repository: boot features from the system repository, file: remote repository, mvn:file:...!g/a/v repository, karaf-web install.
  • Booted karaf-light with a remote repository mirrored to a local HTTP repository by settings.xml: snapshot installed from maven-metadata.xml, newer deployment picked by bundle:update, bundle:watch updating from the configured local repository.
  • Booted the standard distribution with both providers: Pax URL stays in use after feature:install url, and the features service falls back to the Karaf one when the Pax URL provider is stopped.
  • Before the rebase, also checked on karaf-light: restart, wrap:mvn: installs, deploy folder wrapping, feature:install with wrap: bundles, kar:install, child instance create/start.

Known limitations

  • LATEST, RELEASE and version ranges are not resolved, and a timestamped snapshot version is resolved as the newest version of its snapshot.
  • Settings: the encrypted passwords are not supported, and the profiles are only activated by activeProfiles or activeByDefault.
  • The maven:* commands still target the org.ops4j.pax.url.mvn configuration.
  • feature:export-bundles resolves the bundle locations with the MavenResolver service, so it doesn't export wrap: locations.
  • Redirects from http to https are not followed (HttpURLConnection), a file: mirror is used as a remote repository, read timeouts are not retried, and localRepository is a path (not a file: URL).
  • With both providers in the standard distribution, the features service uses the first registered one, so the choice depends on the registration order at startup (the Pax URL one in our tests, after feature:install url and after a restart).

@jbonofre jbonofre linked an issue Mar 18, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Test Results

1 112 files  + 44  1 112 suites  +44   1h 12m 46s ⏱️ - 13m 15s
1 360 tests +150  1 226 ✅ +150  134 💤 ±0  0 ❌ ±0 
5 440 runs  +600  4 902 ✅ +600  538 💤 ±0  0 ❌ ±0 

Results for commit 18f4229. ± Comparison against base commit bb6110f.

♻️ This comment has been updated with latest results.

@jbonofre jbonofre changed the title feat(services): add native karaf.url service as mvn: protocol handler feat(services): add native karaf.url service (mvn: and wrap:) and use it in karaf-light Oct 3, 2026
@jbonofre
jbonofre force-pushed the gh-2332 branch 3 times, most recently from 1e1f014 to 91bb4a6 Compare November 19, 2026 09:27
jbonofre and others added 15 commits November 19, 2026 14:30
Add a new URL handler service under services/url that provides a native
replacement for pax-url-mvn. The service registers a URLStreamHandlerService
for the mvn: protocol and exposes a MavenResolver API for programmatic
artifact resolution from local and remote Maven repositories.
Remove the redundant explicit Bundle-Activator instruction, which
collided with the activator class already detected by
karaf-services-maven-plugin and produced an invalid duplicate-type
manifest header, failing the bundle build. Also embed
org.apache.karaf.util.maven and org.apache.karaf.util.tracker(.annotation),
which are provided-scope dependencies that were not packaged into the
bundle, leaving Parser and BaseActivator unresolved at runtime.
Add a wrap: URL handler to the native Karaf URL service, equivalent to
pax-url-wrap. The handler supports the same syntax
(wrap:jar-url[,instructions-url][$instructions]), the overwrite modes
(keep, merge, full) and the same defaults (optional Import-Package,
Export-Package: *, symbolic name derived from the URL).

The OSGi manifest is generated with bnd, embedded privately in the bundle
(only the used packages, with the OSGi API not provided by the framework),
so all bnd instructions are supported.
…rl service

The features service now resolves mvn: URIs through the
org.apache.karaf.features.spi contract, so the karaf.url service
implements it instead of exposing its own MavenResolver API.

MavenResolverImpl implements org.apache.karaf.features.spi.MavenResolver.
A failed resolution is never retried by the features service, as the
downloads from the remote repositories are already retried
(connection.retryCount).

The bundle registers a MavenResolverFactory, which the features service
uses with the org.apache.karaf.url.mvn configuration, and a ready to use
MavenResolver, used by the components that just resolve an artifact
(feature:export-bundles). The factory is also declared for ServiceLoader,
so it can be used outside the OSGi framework, where the configuration
variables are resolved with the system properties.

The org.apache.karaf.services.url package is removed: the bundle no
longer exports any package.
…bution

The karaf-light distribution now provides the mvn: and wrap: protocols with
the native Karaf URL service instead of pax-url-aether and pax-url-wrap, and
the features service resolves the Maven artifacts with it, through the
Karaf Maven resolver SPI.

- Add the url feature (Karaf URL service at start level 5 and its
  etc/org.apache.karaf.url.mvn.cfg configuration) to the standard features.
- karaf-light uses url as startup feature and blacklists the pax-url-aether
  and pax-url-wrap bundles, and the org.apache.karaf.maven.resolver.paxurl
  provider of the framework feature (the wrap feature stays as marker for
  the wrap deployer and the wrap prerequisites). The unused Pax URL files
  are removed from the assembly.
- The Karaf URL service declares its URL handler capabilities, supports the
  @multi repositories (KAR repositories), and waits for the ConfigAdmin
  configuration when org.apache.karaf.url.mvn.requireConfigAdminConfig is
  set (as in etc/config.properties). Until then, it provides neither the URL
  handlers nor the Maven resolver, so the features service uses the system
  repository.
- Child instances get the Karaf URL service configuration and the features
  processing file of the root instance.
- Document the Karaf URL service provider in the Maven resolver section of
  the manual.
The features service used the last registered MavenResolverFactory and,
when it went away, no factory at all, even if another one was still
registered. Installing the url feature in the standard distribution then
silently replaced the Pax URL resolver, and uninstalling it left the
features service resolving from the system repository only.

The features service now uses the factory with the highest
service.ranking and, for the same ranking, the first registered one (as
BundleContext.getServiceReference() does), and switches to the best
remaining one when the factory in use is unregistered.
…araf.url resolver

- Parse the repositories as Pax URL does: only the known @ options
  (@id=, @snapshots, @noreleases, @multi, ...) are removed, any other @
  is part of the URL. A distribution in /var/jenkins/workspace/job@2 or a
  repository URL with credentials were cut at the first @.
- Authenticate on a remote repository with the credentials of its URL
  (https://user:password@host/...), given to that host only.
- Download each artifact to a temporary file of its own and move it
  atomically, so concurrent downloads of the same artifact do not mix
  their content (as SimpleDownloadTask, apachegh-2808).
- Resolve the file: repositories of the remote repositories list, which
  were skipped.
- Use the repository of mvn:repository_url!groupId/artifactId URLs.
- Accept hand written file: URIs (spaces, relative URIs) as Pax URL does,
  and ignore an invalid repository with a warning instead of failing
  every resolution.
- Reject the artifact paths leading outside of the repositories
  (mvn:a/../.. for instance).
- Fetch the checksums with the same connection settings as the artifact
  (certificateCheck, timeouts, credentials), and fail a download which
  can't be verified with the fail checksum policy, as Maven does.
…tances

A child instance got the etc/org.apache.karaf.features.xml file of the root
instance, but not etc/versions.properties, which provides the values of its
${...} placeholders.
bundle:watch only read the local repository of the org.ops4j.pax.url.mvn
configuration, so in the karaf-light distribution it watched
~/.m2/repository instead of the configured local repository. Without Pax URL
configuration, it now uses the org.apache.karaf.url.mvn one.

The options of the local repository (@id=...) are now removed as for the
repositories: the path was replaced by the part starting at its first @,
which also broke the paths containing @ (/var/jenkins/workspace/job@2).
…tamped snapshot

When a resolution failed, MavenDownloadTask resolved the artifact again
without the snapshot timestamp, even when its URL had none, so each missing
artifact was resolved twice with the same URL.
…gs in the karaf.url resolver

- Resolve the snapshots from the maven-metadata.xml files of the remote
  repositories (Maven 3 snapshotVersions and Maven 2 timestamps), using the
  newest version, and keep the local copy when it is newer or when the
  repositories can't be reached. As Maven, the metadata of each repository
  is kept in the local repository, and checked again as the update policy
  (globalUpdatePolicy, daily by default) tells.
- Enforce @snapshots and @noreleases on the remote repositories.
- Read the Maven settings (settings property, else ~/.m2/settings.xml,
  ${maven.home}/conf/settings.xml, ${M2_HOME}/conf/settings.xml): local
  repository, repositories of the active profiles (when repositories is not
  set, or appended when it starts with +), credentials of the servers,
  mirrors and proxies.
- Without configuration, use the default repositories of the Karaf instance
  and the remote repositories of etc/org.apache.karaf.url.mvn.cfg, and log
  it, instead of ~/.m2/repository only.
- Only retry the downloads which may succeed (server errors, rate limit,
  connection reset, checksum mismatch), with an increasing delay, and not an
  unknown host, a refused connection, a timeout or a client error. The
  resolution error now gives the error of each repository, and the error
  responses are read so the connections can be reused.
- Substitute the variables of the configuration once, with the Felix
  InterpolationHelper (default values, nested variables), embedded in the
  bundle.
- Remove the resolve(groupId, artifactId, classifier, extension, version)
  override, which dropped an empty version: the SPI default method is used.
- Document the settings, the defaults and the policies in the
  configuration.
…cies of the karaf.url resolver

- Compare the version of a remote snapshot with the one of the local copy, as
  Maven does: its maven-metadata-local.xml when it was installed, else the
  version it was downloaded with (in karaf-url-status.properties, as long as
  the file is not replaced). The modification time of the local copy was used,
  so a snapshot deployed by a build started before the download, or any
  snapshot when the local repository was copied, was never resolved.
- Without metadata in the repositories, don't download a snapshot the local
  repository already has: its version can't be compared, so it was downloaded
  again on each resolution, even over a newer local build. The
  maven-metadata-local.xml of a file: repository is read.
- Use the http proxy of the Maven settings for the https repositories when
  there is no https proxy, as Maven does.
- Apply the @update=, @snapshotsUpdate=, @Checksum=, @releasesChecksum= and
  @snapshotsChecksum= options of the repositories when the global policies are
  not set, as Pax URL does, and read the checksum policies case insensitively.
- Don't use the repository id, which may come from the URL, as a path in the
  name of the metadata cache file.
…f a karaf-light instance

A child of a root instance starting the Karaf URL service got
etc/org.ops4j.pax.url.mvn.cfg, so bundle:watch used the local repository of
the Pax URL configuration (~/.m2/repository by default) instead of the
configured one. As the logging configuration, it now only gets it when the
root instance starts Pax URL.
…af home directory

As the Karaf URL service, bundle:watch resolves a relative local repository of
the org.apache.karaf.url.mvn configuration in the Karaf home directory, not in
the working directory.
… fallback and NOTICE in karaf.url

- Strip repository options and support file: URIs on localRepository in MavenConfiguration/Repository
- Split wrap: URLs without regex ambiguity and allow valid OSGi header value characters in WrapUrlParser
- Fall back across snapshot repositories ordered by metadata timestamp and decode checksums as UTF-8 in MavenResolverImpl
- Quote literal segments in MavenSettings nonProxyHosts wildcard matching
- Add bnd notice to assemblies/apache-karaf-light NOTICE
@jbonofre
jbonofre merged commit 981a583 into apache:main Nov 20, 2026
13 of 14 checks passed
@jbonofre
jbonofre deleted the gh-2332 branch November 20, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Karaf URL service

1 participant