Repository navigation
Conversation
jbonofre
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fix!
Nit: the split local repo handling in MojoSupport assumes the pax-url option names and defaults match Maven's aether.enhancedLocalRepository.* semantics. A pax-url upgrade could change that silently. The new test covers only split plus splitLocal, so a test for the prefix options would help later.
| * Prefix of the Maven resolver (1.9+) configuration properties for the split local repository. | ||
| */ | ||
| private static final String ENHANCED_LOCAL_REPOSITORY = "aether.enhancedLocalRepository."; | ||
|
|
There was a problem hiding this comment.
Please consider extracting the 2d arrays as static constants
| private static final String[][] OPTIONS = { | |
| { ENHANCED_LOCAL_REPOSITORY + "split", ServiceConstants.OPTION_SPLIT }, | |
| { ENHANCED_LOCAL_REPOSITORY + "splitLocal", ServiceConstants.OPTION_SPLIT_LOCAL }, | |
| { ENHANCED_LOCAL_REPOSITORY + "splitRemote", ServiceConstants.OPTION_SPLIT_REMOTE }, | |
| { ENHANCED_LOCAL_REPOSITORY + "splitRemoteRepository", ServiceConstants.OPTION_SPLIT_REMOTE_REPOSITORY }, | |
| { ENHANCED_LOCAL_REPOSITORY + "splitRemoteRepositoryLast", ServiceConstants.OPTION_SPLIT_REMOTE_REPOSITORY_LAST } | |
| }; | |
| private static final String[][] PREFIXES = { | |
| { ENHANCED_LOCAL_REPOSITORY + "localPrefix", ServiceConstants.OPTION_SPLIT_LOCAL_PREFIX }, | |
| { ENHANCED_LOCAL_REPOSITORY + "remotePrefix", ServiceConstants.OPTION_SPLIT_REMOTE_PREFIX }, | |
| { ENHANCED_LOCAL_REPOSITORY + "releasesPrefix", ServiceConstants.OPTION_SPLIT_RELEASES_PREFIX }, | |
| { ENHANCED_LOCAL_REPOSITORY + "snapshotsPrefix", ServiceConstants.OPTION_SPLIT_SNAPSHOTS_PREFIX } | |
| }; |
With this, we wouldn't have to concat the strings each time #getPaxUrlLocalRepository is called.
There was a problem hiding this comment.
Thanks for the review @CptBartender. Agreed, extracting the tables to static constants makes getPaxUrlLocalRepository easier to read.
@ponziani you call if you wanna apply it? One caveat: the suggested keys already include ENHANCED_LOCAL_REPOSITORY, so the loops need to look them up directly with configProperties.get(option[0]) and configProperties.get(prefix[0]). Otherwise the prefix gets applied twice and no option matches. testLocalRepositoryWithSplit should catch that if it's missed.
Since the order of the generated options (@split@splitLocal@...) is asserted in the tests, please keep the declaration order. If you would rather not expose mutable arrays, an ordered immutable structure such as a List of pairs or a LinkedHashMap wrapped in Collections.unmodifiableMap works too.
Also, the test already covers splitLocalPrefix and splitSnapshotsPrefix, so only remotePrefix and releasePrefix are missing. Adding those to testLocalRepositoryWithSplit while you are in there would close that gap.
There was a problem hiding this comment.
Thanks @CptBartender, applied: the options and prefixes are now static constants holding the full property keys, in the same order. Thanks @jbonofre for spotting the double-prefix catch. I also added remotePrefix and releasesPrefix to testLocalRepositoryWithSplit, so all four prefixes are covered now.
a8e49e1 to
a96394b
Compare
|
Rebased on It would be nice if this makes into the 4.5 release. |
a96394b to
02f22a6
Compare
| import org.apache.maven.project.ProjectBuildingException; | ||
| import org.apache.maven.settings.Proxy; | ||
| import org.codehaus.plexus.PlexusContainer; | ||
| import org.ops4j.pax.url.mvn.ServiceConstants; |
There was a problem hiding this comment.
You offered to move this behind the SPI in a follow-up. I'd rather sort it out in this PR. Since #2928, the plugin and Builder don't import anything from org.ops4j. They only talk to the resolver through org.apache.karaf.features.spi.MavenResolverFactory, so pax-url can be replaced by another provider. This import brings pax-url back into the plugin. The @id=local@split... value is also pax-url-specific syntax passed through that neutral interface, so any other provider would read it as a literal directory. The new test likewise builds its resolver with pax-url's MavenResolvers instead of org.apache.karaf.features.spi.MavenResolvers.factory().
The ReactorMavenResolver approach from my comment on ENHANCED_LOCAL_REPOSITORY avoids this, since the lookup goes through Maven's own session and needs nothing from the provider. It would also keep the 4.4.x backport the same shape, since that branch has no resolver-paxurl module. If you'd rather keep the configuration approach, please move the pax-url mapping into PaxUrlMavenResolverFactory and give it provider-neutral settings.
| /** | ||
| * Prefix of the Maven resolver (1.9+) configuration properties for the split local repository. | ||
| */ | ||
| private static final String ENHANCED_LOCAL_REPOSITORY = "aether.enhancedLocalRepository."; |
There was a problem hiding this comment.
This only reads the aether.enhancedLocalRepository.* names. Maven Resolver 2.x (used by Maven 3.10, which Karaf itself builds against, and by Maven 4) documents aether.lrm.enhanced.* instead and keeps the old names only as fallbacks. Resolver 2.0.24's LocalPathPrefixComposerFactorySupport reads both sets.
So with -Daether.lrm.enhanced.split=true -Daether.lrm.enhanced.splitLocal=true, Maven installs the SNAPSHOT under installed/snapshots/..., but this method returns the plain directory. Assembly and verify then still fail with "Could not find artifact" (reproduced with pax-url 3.0.3). KARAF-7667 stays open for anyone following the current Maven docs.
Rather than copying Maven's settings into pax-url, could ReactorMavenResolver ask Maven where the artifact is first? mavenSession.getRepositorySession().getLocalRepositoryManager().find(...), called with the project's remote repositories and using the file when isAvailable(), works whatever layout Maven is using: split with either key set, custom prefixes, trackingFilename, maven.repo.local.tail. Both goals already wrap their resolver in ReactorMavenResolver, and pax-url could keep the plain directory. If you'd rather keep passing the settings to the resolver, it needs to read both key sets (new names taking precedence). See my comment on the import about where that mapping should live.
| Dictionary<String, String> props = new Hashtable<>(); | ||
| if (offline) { | ||
| props.put(pid + "offline", "true"); | ||
| props.put(pid + ".offline", "true"); |
There was a problem hiding this comment.
The key fix is right, but it changes every mvn -o assembly build, not only split-repository ones. Until now the misspelled key meant pax-url always stayed online, so under -o it quietly fetched feature bundles that Maven itself never resolved. With this change:
- a bundle referenced only from a features.xml and not yet in the local repository now fails the build instead of being downloaded;
- an artifact cached under a different repository id (
_remote.repositoriessaysnexus, pax-url is configured withcentral) now fails with "Cannot access central ... in offline mode and the artifact has not been downloaded from it before", where it used to succeed.
That's arguably what -o should mean, but it's a visible behaviour change for existing builds, and the description proposes taking it to karaf-4.4.x too. Could you move this to its own PR and JIRA, with an invoker IT that runs an assembly offline and a release note? Today the test-offline invoker execution excludes all three assembly ITs (test-assembly, test-assembly-prop-edits, test-dockerfile), so nothing covers this path.
| getLog().info("Using repositories: " + remoteRepositories); | ||
| config.put("maven.repositories", remoteRepositories); | ||
| config.put("maven.localRepository", localRepo.getBasedir()); | ||
| config.put("maven.localRepository", getPaxUrlLocalRepository()); |
There was a problem hiding this comment.
Whichever PR ends up carrying the Builder offline fix, the verify goal needs it too. The resolver created at line 203 never gets maven.offline, so under mvn -o assembly resolves offline while verify still contacts the remote repositories (timeouts behind a firewall, downloads despite -o). Something like:
if (mavenSession.isOffline()) {
config.put("maven.offline", "true");
}Ideally with a test checking that both goals honour -o.
02f22a6 to
a25b3e2
Compare
|
Thanks @jbonofre, I took the
Rebased on current |
|
@ponziani thanks for the update, I gonna take a new look. |
ReactorMavenResolver, used by the assembly and verify goals, now looks up artifacts in the local repository of the Maven session, through its LocalRepositoryManager, before it delegates to the MavenResolverFactory provider. Artifacts are found whatever layout Maven uses: a split local repository with the aether.lrm.enhanced.* or the older aether.enhancedLocalRepository.* names, custom prefixes, or maven.repo.local.tail. The lookup is only done with the enhanced local repository. It takes installed artifacts, cached releases, and cached SNAPSHOTs when Maven is offline. Cached SNAPSHOTs when online, version ranges, LATEST/RELEASE and URLs that name their own repository still go to the provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a25b3e2 to
ab162a8
Compare
|
The first CI run of the update failed in |
Fixes KARAF-7667.
Problem
Since Maven 3.9 the local repository can be split into installed and cached artifacts, and further into releases and snapshots or by remote repository (docs). Maven Resolver 2.x (Maven 3.10, Maven 4) uses the
aether.lrm.enhanced.*properties for this and still reads the olderaether.enhancedLocalRepository.*names.The
assemblyandverifygoals resolve artifacts through theMavenResolverFactoryprovider (pax-url), which only gets the plain local repository directory. With a split local repository the plugin cannot find the artifacts installed by an earlier build, typically SNAPSHOTs underinstalled/snapshots/..., and the build fails with "Could not find artifact".Fix
ReactorMavenResolver, which both goals already use, now asks Maven where the artifact is before it delegates to the provider:LocalRepositoryManager#find(...)of the Maven session, with the project's remote repositories and theprojectcontext;MavenResolverFactoryprovider.Maven's own local repository manager does the lookup, so every layout works: split with either set of property names, custom prefixes,
maven.repo.local.tail. The plugin does not depend on pax-url for this, and no provider-specific syntax goes through the SPI.Step 2 is only done with the enhanced local repository (the Maven default), because only that one records where an artifact comes from. It takes:
Everything else goes to the provider as before: cached SNAPSHOTs when online (so its update policy applies), version ranges,
LATEST/RELEASE, URLs that name their own repository (mvn:http://...!g/a/v), and every artifact with the simple local repository (-llr).Behaviour change
This applies to every build with the enhanced local repository, not only to split builds:
Tests
ReactorMavenResolverLocalRepositoryTestuses Maven Resolver's realEnhancedLocalRepositoryManager(test-scopedmaven-resolver-impl). It covers a SNAPSHOT installed withaether.lrm.enhanced.split/splitLocal, the same with the oldaether.enhancedLocalRepository.*names, custom prefixes, cached releases (also from a repository manager, which tracks the context), a cached SNAPSHOT online and offline, and version ranges andLATEST/RELEASE, which have no file of their own and go to the provider. It usesorg.eclipse.aether.internal.implconstructors because that is the only way to get the real manager without a full repository system. A Resolver upgrade that changes them shows at compile time.ReactorMavenResolverTestcovers the cases the real manager cannot easily produce: the request it gets (repositories and context), an unavailable or missing file,-llr, URLs with a repository, and reactor precedence.-Daether.lrm.enhanced.split=true -Daether.lrm.enhanced.splitLocal=trueand an empty local repository: a bundle1.0-SNAPSHOTis installed (intoinstalled/snapshots/...), then akaraf-assemblyproject lists it instartupBundles.Could not find artifact org.example.e2e:e2e-lib:jar:1.0-SNAPSHOT;BUILD SUCCESS, and the bundle is insystem/andetc/startup.properties.The
verifygoal uses the same resolver wrapper and was not run end-to-end.Not in this PR
The
Builderoffline key (pid + "offline", missing dot) and the missingmaven.offlineinVerifyMojochange everymvn -oassembly build. They will go into a separate JIRA and PR with an offline assembly IT and a release note.Backport
The main code only uses Maven Resolver API that also exists in 1.x (
LocalRepositoryManager#find,LocalArtifactResult), so it should apply tokaraf-4.4.x. The real-manager test uses Resolver 2.x internals and would need adapting there.🤖 Generated with Claude Code