Maven Bundle Plugin生成的OSGi Bundle Manifest中内部依赖版本范围异常排查求助
Let's break down why your Maven bundle plugin is generating unexpected version ranges for the com.xxxxxx.yyyy.m2m.* packages, even though your project and dependencies are on 9.0.0-SNAPSHOT. Here are the most likely causes and actionable steps to diagnose them:
1. Verify the actual Bundle-Version in your dependency JARs
The Maven Bundle Plugin doesn’t use the Maven dependency version directly to calculate import ranges—it relies entirely on the Bundle-Version field in the dependency’s MANIFEST.MF. This is a common gotcha!
- Navigate to your local Maven repo:
.m2/com/xxxxxx/yyyy/m2m/com.xxxxxx.yyyy.m2m.config/9.0.0-SNAPSHOT - Unpack the JAR file and open
META-INF/MANIFEST.MF - Check the
Bundle-Versionvalue. If it’s something like8.1.0instead of9.0.0.SNAPSHOT, that’s exactly why the plugin generates[8.1,9)as the import range.
This usually happens if the com.xxxxxx.yyyy.m2m.config module wasn’t properly rebuilt with the 9.0.0-SNAPSHOT version in its own bundle configuration.
2. Check your Maven Bundle Plugin version and configuration
Your plugin version is 4.2.0, which is quite old (released in 2019). Older versions might have bugs in version range calculation, especially with SNAPSHOT dependencies.
- Try upgrading the plugin to the latest stable version (e.g., 5.1.9) in your POM:
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>5.1.9</version> <extensions>true</extensions> <configuration> <!-- your existing instructions --> </configuration> </plugin> - Also, check if there’s any explicit configuration in your plugin’s
<instructions>(or inherited from the parent POM) that’s overriding the import range form2mpackages. Look for any<Import-Package>entries that might hardcode versions for these packages.
3. Rule out parent POM or global Maven configuration issues
Your project inherits from a parent POM (yyyy-features), so it’s possible that parent is applying bundle plugin settings you’re not aware of:
- Inspect the parent POM’s
<build><plugins>section for anymaven-bundle-pluginconfigurations that might be setting default import rules. - Check your global
settings.xml(usually in~/.m2/settings.xml) for profiles or mirrors that might be pulling an older cached version of them2mdependency instead of the latest SNAPSHOT.
4. Ensure your SNAPSHOT dependencies are properly built
Even if mvn dependency:tree shows the correct version, the actual JAR in your repo might be stale:
- Navigate to the
com.xxxxxx.yyyy.m2m.configmodule’s source code and runmvn clean installto force a full rebuild. - After rebuilding, double-check the MANIFEST.MF in the newly built JAR to confirm the
Bundle-Versionis9.0.0.SNAPSHOT. - Then run
mvn clean installon your currentcommandmodule and check the generated MANIFEST again.
5. Temporary workaround: Force the import range
If you need a quick fix while troubleshooting, you can explicitly define the import range in your bundle plugin configuration to override the automatic calculation:
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Export-Package>com.xxxxxx.yyyy.command.*</Export-Package> <Karaf-Commands>*</Karaf-Commands> <Import-Package> com.xxxxxx.yyyy.m2m.*;version="[9.0,10)", * <!-- Keep this to auto-generate other imports --> </Import-Package> </instructions> </configuration> </plugin>
This will ensure all m2m packages use the expected [9.0,10) range while letting the plugin handle other imports normally.
内容的提问来源于stack exchange,提问作者maxence pecheux

