问题
With Eclipse Oxygen.2 Release (4.7.2), I'm trying to use bndtools to make some OSGi bundles.
By default (with the JPM repository) I am able to resolve dependencies fine. But I have no way of seeing what libraries are there. Because of this, I'd like to use Maven Central to handle my dependencies. I can browse the website, see what versions are there, and make choices on that information.
The default build.bnd
file in the cnf
project has the repositories setup like
# Configure Repositories
-plugin.1.Central: \
aQute.bnd.deployer.repository.wrapper.Plugin; \
location = "${build}/cache/wrapper"; \
reindex = true, \
aQute.bnd.jpm.Repository; \
includeStaged = true; \
name = Central; \
location = ~/.bnd/shacache; \
index = ${build}/central.json
-plugin.2.Local: \
aQute.bnd.deployer.repository.LocalIndexedRepo; \
name = Local; \
pretty = true; \
local = ${build}/local
-plugin.3.Templates: \
aQute.bnd.deployer.repository.LocalIndexedRepo; \
name = Templates; \
pretty = true; \
local = ${build}/templates
-plugin.4.Release: \
aQute.bnd.deployer.repository.LocalIndexedRepo; \
name = Release; \
pretty = true; \
local = ${build}/release
Following the instructions on the bnd website I added the following to my file; because there was already a Central
repository, I named this one Maven
but the rest is the same
-plugin.5.Maven = \
aQute.bnd.repository.maven.provider.MavenBndRepository; \
releaseUrl=https://repo.maven.apache.org/maven2/; \
index="${.}/central.maven"; \
name="Maven"
When I remove the JPM repository, suddenly everything is broken. This didn't come as too much of a surprise, because I did just remove a repository. However, I thought that after building and cleaning the workspace, it would resolve that we can access maven central, and it would pull from there. This was not the case.
I noticed that there was an index
property on the Maven repository, so I thought that perhaps I had to add all of my dependency names to the file specified, but I haven't been able to find any documentation on what the file looks like, or how to create one, or anything of the sort.
The errors that I get in Eclipse are
Cannot find /error/org.apache.servicemix.bundles.junit;version=4.12 Not found in [bnd-cache [PATH\TO\WORKSPACE\cnf\cache\3.5.0\bnd-cache r/w=false], Local, Templates, Release, MavenBndRepository [localRepo=PATH\TO\USER\FOLDER.m2\repository, storage=Maven, inited=true]]
Is there something I'm missing in this whole process? Is there something obvious I've missed?
回答1:
I found out (thanks to the OSGi enroute tutorial), what I was missing.
There needs to be an existing index file at the specified location, and that file is made up of maven coordinate entries. The jpm index only needed the artifact id and version, but the maven coordinates require group, artifact, and version.
I modified my cnf/build.bnd
entry to look like
-plugin.5.Central = \
aQute.bnd.repository.maven.provider.MavenBndRepository; \
releaseUrl=https://repo.maven.apache.org/maven2/; \
name="Central"
I removed the index file specification, that way it would just use the default (cnf/<name>.mvn
). However, I wasn't sure which name the documentation was talking about. I determined that it was the name specified inside the repository settings. name="<ThisValueHere>"
, not -plugin.5.<ThisValueHere>
. Note that this value is not case-sensitive.
My central.mvn
file ended up looking like
org.apache.felix:org.apache.felix.framework:5.4.0
org.apache.felix:org.apache.felix.gogo.command:1.0.2
org.apache.felix:org.apache.felix.gogo.runtime:1.0.10
org.apache.felix:org.apache.felix.gogo.shell:1.0.0
org.apache.felix:org.apache.felix.log:1.0.1
org.apache.felix:org.apache.felix.scr:2.0.14
org.apache.servicemix.bundles:org.apache.servicemix.bundles.junit:4.12_1
org.osgi:osgi.annotation:6.0.1
org.osgi:osgi.cmpn:6.0.0
org.osgi:osgi.core:6.0.0
来源:https://stackoverflow.com/questions/48361979/unable-to-use-maven-central-repository-with-bnd-to-resolve-dependencies