Maven + Tycho, adding Maven dependencies

We have an Eclipse plugin that we create using Maven and Tycho. At the moment, however, we still provide all the project dependencies through a bunch of manually added JAR files, not Maven. This is due to the following reasons: (1) dependencies are not available through the standard Eclipse update site (at least not in the current version), (2) dependencies are not available as packages.

Most of these dependencies are Selenium libraries (APIs, Remote, browser-specific libraries and their transitive dependencies, such as Guava, etc.)

I spent several hours trying to pull out these dependencies during the build of Maven. Following this SO question, I tried p2-maven-plugin , created an update site with our dependencies, which I added to my target Eclipse platform. However, at runtime, the classes referenced by different JARs cannot be (I suppose from my very limited knowledge of OSGi, because some of the necessary information was missing in the MANIFEST.MF files). Here is an example of a problem when trying to create a RemoteWebDriver that uses DesiredCapabilities (both classes in different packages):

 Exception in thread "Thread-8" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/DesiredCapabilities at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:243) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153) … Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.DesiredCapabilities cannot be found by org.seleniumhq.selenium.remote-driver_2.45.0 at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344) at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more 

Is there anything else I need to take care of when using the p2-maven-plugin ? The relevant parts of pom.xml looked like this:

 <plugin> <groupId>org.reficio</groupId> <artifactId>p2-maven-plugin</artifactId> <version>1.1.1-SNAPSHOT</version> <executions> <execution> <id>default-cli</id> <configuration> <artifacts> <artifact> <id>org.seleniumhq.selenium:selenium-remote-driver:2.45.0</id> </artifact> </artifacts> </configuration> </execution> </executions> </plugin> 
+5
source share
3 answers

Failed to get it working, so we now use the maven-dependency-plugin with copy-dependencies , which we execute during the Maven initialize phase to pull out all the necessary dependencies (contrary to my initial feeling, this can be combined with pom.xml using eclipse-plugin packaging and manifest first approach). The relevant part is as follows:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>initialize</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> </plugins> </build> 

Then the Maven dependencies are copied to target/dependency .

Just a minor issue: The Bundle-ClassPath in MANIFEST.MF needs to be updated manually if the JAR file name changes when updating Maven dependencies (for example, commons-io-2.4.jar becomes commons-io-2.5.jar ).

[edit] Reviewing this answer again for the last sentence above: version numbers can be easily removed with the following option: <stripVersion>true</stripVersion> . This means that the above library will be renamed commons-io.jar , and therefore no paths should be updated when the version number changes.

+9
source

Another possibility:

Some jar files may get corrupted (if you use Eclipse, is this commonplace hibernate-commons-annotations-4.0.1.Final.jar; invalid LOC header (bad signature)? ). To test this feature, try manually opening the jar to make sure everything is in order.

0
source

I also create an Eclipse plugin with Maven and Tycho. I have the same problem: the org.eclipse.team.svn.core and org.eclipse.team.svn.ui packages are not available through the standard Eclipse update site.

Perhaps you can try this to solve this problem:

  • In Dependencies, find the Dependencies Automated Control field.
  • Add the desired plugin using Add ...
  • Select Code Analysis and add the dependencies to MANIFEST.MF via: Import Package
  • Click Add Dependencies to find the packages you need in the Imported Packages field.

Then you can start the Maven build.

0
source

Source: https://habr.com/ru/post/1239217/


All Articles