p2-maven-plugin
p2-maven-plugin copied to clipboard
Is a HTTP server really necessary to provide the p2 site?
Hi, first of all let me thank you for making this plug-in! I've just started using it recently on a new project, and it has been immensely helpful for using Java libraries that are outside of the OSGi/p2 world (a lot of them, especially newer ones!).
One thing though, the README mentions using the Jetty HTTP server to provide a p2 site, but is that really necessary? Are there problems with using a relative "file:/" URL? I've tried this in a skeleton example and it seems to work well so far. You can see the example here: https://github.com/bruno-medeiros/eclipse-examples/tree/master/full_skeleton
Specifically this is used:
<repository>
<id>maven_deps</id>
<layout>p2</layout>
<url>file:maven_deps/target/repository</url>
</repository>
The restriction here is that for the Eclipse PDE development environment the target platform will need to be configured with the absolute path, which is machine-specific setting - therefore each developer will have to do this configuration step manually. That is fine in this case though, and the target platform is not used for the Tycho build, but just for the dev environment.
Yes, it is (more or less): Using Tycho for automatic build of Eclipse projects, only supports software sites (via http) not via file:-URL. I can't answer the question why Tycho never has been enabled with this valid feature request yet.
The PDE supports file URLs containing Eclipse variables like ${project_loc:..}
. Tycho 1.x also supports file URLs in target platforms, but they have to be absolute URLs. That makes everything hard to handle since Tycho does not support any kind of variables in .target files. You can actually use the same target platform with Tycho and PDE without HTTP server as long as all file URLs are absolute. That's makes automated builds a bit harder but I guess you could probably generate the target platform with absolute URLs on each machine (in a separate step before the regular build, because as far as I know it's not possible to execute any plugins before Tycho loads the target platform).
Anyway I just saw the release notes for Tycho 2.0 which say that directories are supported now and also a few variables. I haven't tried it yet but maybe it can be used to lift some of the restrictions.
I tried latest Tycho 2.1.0. Tycho now supports "directory" locations in target files with support for ${project_loc:..}
variables (currently there's an issue with Windows paths - that will be fixed in 2.2.0). These variables aren't supported in p2 repository URLs though. So if you are ok with using directories instead of local p2 repositories, you can now use the same target platform both with PDE any Tycho. Throwing a bunch of bundle jars in a directory may not be the most sophisticated solution but at least you don't have to deal with either separate target definitions for PDE and Tycho or hosting a p2 site.
But maybe even better is that Tycho 2.1.0 also supports automatic conversion of non-osgi Maven artifacts to bundles when using pomDependencies=consider
. That means you can use any Maven artifact in your Tycho build without any additional steps! Currently that feature is quite basic but it seems there are plans to extend native support of Maven artifacts in Tycho in the future. I'm not sure what that means for the future of p2-maven-plugin though. p2-maven-plugin was really helpful in some cases and reduced pain points of Tycho. Will the p2-maven-plugin become obsolete? Some Tycho commiters say so in this discussion.
I also used (absolute) file-URLs to the p2 repo created by the p2-maven-plugin in my target-file (just for quick checking/prototyping) and can confirm that it works well with current tycho.
It would be great if the README.md were updated and say that jetty is not necessary in most cases. This makes things now very easy. Nevertheless it's probably useful to keep the note about jetty as back-up for cases where the regular options don't work.
@HannesWell Thank you for your advice. It would be great if you could prepare a PR for updating the Readme with your advice.