Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pom dependencies in maven target locations doesn't work for transitive dependencies (includeDependencyScope) #684

Closed
henryju opened this issue Feb 24, 2022 · 9 comments
Milestone

Comments

@henryju
Copy link

henryju commented Feb 24, 2022

Hi,

I'm trying to replace my pom first dependencies by Maven dependencies in my target file. I am using Tycho 2.6.0.

It works fine for simple dependencies that don't have any transitive one.

But if I try to use something like:

  <location includeDependencyScope="compile" includeSource="true" missingManifest="error" type="Maven">
    <dependencies>
      <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>3.7.7</version>
        <type>jar</type>
      </dependency>
    </dependencies>
  </location>

then in Eclipse it works fine (transitive dependencies are correctly resolved):
image
and running tests from Eclipse works.

But from Tycho command line, I get:

mvn clean verify
[...]
[INFO] Resolving MavenDependencyRoots = [GroupId = org.mockito, ArtifactId = mockito-core, Version = 3.7.7, ArtifactType = jar, IncludeDependencyScope = ], IncludeDependencyScope = compile, MissingManifestStrategy = ERROR, IncludeSource = true...
[...] // No mention of bytebuddy or objenesis
[INFO] --- tycho-surefire-plugin:2.6.0:test (default-test) @ org.sonarlint.eclipse.core.tests ---
[...]
Running org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.028 s <<< FAILURE! - in org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest
test(org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest)  Time elapsed: 0.013 s  <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest.test(BuildWrapperJsonFactoryTest.java:51)
Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker
        at org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest.test(BuildWrapperJsonFactoryTest.java:51)
Caused by: java.lang.reflect.InvocationTargetException
        at org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest.test(BuildWrapperJsonFactoryTest.java:51)
Caused by: java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/loading/ClassInjector$UsingReflection
        at org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest.test(BuildWrapperJsonFactoryTest.java:51)
Caused by: java.lang.ClassNotFoundException: net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection cannot be found by org.mockito.mockito-core_3.7.7
        at org.sonarlint.eclipse.cdt.internal.BuildWrapperJsonFactoryTest.test(BuildWrapperJsonFactoryTest.java:51)
@laeubi
Copy link
Member

laeubi commented Feb 25, 2022

This is not a problem of transitive deps not working but most probably of missing requirements of your test.

You should add the bytebuddy as an requirement to your test (import package or require bundle) so tycho could include it in the test-runtime.

@henryju
Copy link
Author

henryju commented Feb 25, 2022

but most probably of missing requirements of your test

In the current working state, I am using a pom dependency (with pomDependencies=consider) on mockito-core only, and it is correctly working in Tycho. Why would moving the Maven dependency from the pom to the target platform require a change in my tests?
Also, my tests have a dependency on assertj-core bundle, that in turn has Import-Package: net.bytebuddy; in its MANIFEST. So shouldn't it be enough for Tycho to properly resolve bytebuddy from the target platform?
Lastly, it works in PDE, so I'm tempted to think it should work on Tycho without modification.

In addition, from an OSGi point of view, my tests have no dependency on bytebuddy, so it sounds wrong to me to add one "just" to help Tycho to resolve properly the dependency chain.

@laeubi
Copy link
Member

laeubi commented Feb 25, 2022

All these are good questions but hard to answer without an example project showing the problem.
You could provide an integration-test to demonstrate the issue so we can investigate this further.

@laeubi
Copy link
Member

laeubi commented Feb 25, 2022

Also please keep in mind that compile might be not enough here and you require test as a dependency scope. There where some issues in m2e and tycho in older versions regarding incorrect filtering of dependency scopes. This will be fixed with the next release.

@henryju
Copy link
Author

henryju commented Mar 1, 2022

In fact there is exactly an IT for that already: https://github.com/eclipse/tycho/blob/master/tycho-its/projects/target.maven-scopes/test.target

As you suggested, the IT works because the test bundle explicitly declare a dependency on objenesis and bytebuddy.

I checked again, and contrary to what I said earlier, this is not working in PDE without an explicit dependency on objenesis and bytebuddy.

What was working before (and I don't really understand why it makes a difference) is having a directory type location in my target platform. Possibly in this case PDE will eagerly put the bundle in the runtime?

So I think we can close this ticket, sorry for the noise.

@laeubi
Copy link
Member

laeubi commented Mar 8, 2022

No problem, please let us know if you find out what might mkaes the difference so we could potentially improve tycho here!

@laeubi laeubi closed this as completed Mar 8, 2022
@laeubi laeubi added this to the 3.0 milestone Sep 21, 2022
@vlsi
Copy link

vlsi commented Nov 11, 2023

Is there a way to automatically generate Require-Bundle based on pom.xml dependencies?

I want adding the following dependency:

<dependency>
    <groupId>org.apache.calcite</groupId>
    <artifactId>calcite-core</artifactId>
    <version>1.36.0</version>
</dependency>

In practice, it has many dependencies, some of which are bundles, and some are not:

[INFO] +- net.minidev:accessors-smart:jar:2.5.0:compile
[INFO] |  \- org.ow2.asm:asm:jar:9.3:compile
[INFO] +- net.minidev:json-smart:jar:2.5.0:compile
[INFO] +- org.apache.calcite:calcite-core:jar:1.36.0:compile
[INFO] |  +- org.apache.calcite:calcite-linq4j:jar:1.36.0:compile
[INFO] |  +- org.locationtech.jts:jts-core:jar:1.19.0:compile
[INFO] |  +- org.locationtech.jts.io:jts-io-common:jar:1.19.0:compile
[INFO] |  |  \- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] |  +- org.locationtech.proj4j:proj4j:jar:1.2.2:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.0:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.21.1:compile
[INFO] |  +- org.apache.calcite.avatica:avatica-core:jar:1.23.0:compile
[INFO] |  |  +- org.apache.calcite.avatica:avatica-metrics:jar:1.23.0:compile
[INFO] |  |  +- com.google.protobuf:protobuf-java:jar:3.21.9:compile
[INFO] |  |  +- org.apache.httpcomponents.client5:httpclient5:jar:5.1.3:runtime
[INFO] |  |  |  \- org.apache.httpcomponents.core5:httpcore5-h2:jar:5.1.3:runtime
[INFO] |  |  \- org.apache.httpcomponents.core5:httpcore5:jar:5.1.3:runtime
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] |  +- org.checkerframework:checker-qual:jar:3.37.0:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.33:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.15.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.15.0:compile
[INFO] |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.15.0:runtime
[INFO] |  |  \- org.yaml:snakeyaml:jar:2.0:runtime
[INFO] |  +- com.google.uzaygezen:uzaygezen-core:jar:0.2:runtime
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.7.0:runtime
[INFO] |  +- com.yahoo.datasketches:sketches-core:jar:0.9.0:runtime
[INFO] |  |  \- com.yahoo.datasketches:memory:jar:0.9.0:runtime
[INFO] |  +- commons-codec:commons-codec:jar:1.13:runtime
[INFO] |  +- net.hydromatic:aggdesigner-algorithm:jar:6.0:runtime
[INFO] |  |  +- commons-lang:commons-lang:jar:2.4:runtime
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.3:runtime
[INFO] |  +- org.apache.commons:commons-dbcp2:jar:2.9.0:runtime
[INFO] |  |  \- org.apache.commons:commons-pool2:jar:2.10.0:runtime
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.12.0:runtime
[INFO] |  +- org.apache.commons:commons-math3:jar:3.6.1:runtime
[INFO] |  +- org.apache.commons:commons-text:jar:1.10.0:runtime
[INFO] |  +- commons-io:commons-io:jar:2.11.0:runtime
[INFO] |  +- org.codehaus.janino:commons-compiler:jar:3.1.9:runtime
[INFO] |  \- org.codehaus.janino:janino:jar:3.1.9:runtime
[INFO] +- com.google.guava:guava:jar:32.1.3-jre:compile
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  \- com.google.j2objc:j2objc-annotations:jar:2.8:compile
[INFO] \- com.google.code.findbugs:jsr305:jar:3.0.2:compile

I tried adding <pomDependencies>wrapAsBundle</pomDependencies>, however, it looks like I still need to manually list all the dependencies with MANIFEST.MF/Require-Bundle which is hard to do manually, especially taking into the account that some of the dependencies are bundles.

Is there a way to use something like Require-Bundle: <target-platform-name> so it requires all the bundles from the platform?

@laeubi
Copy link
Member

laeubi commented Nov 11, 2023

Is there a way to automatically generate Require-Bundle based on pom.xml dependencies?

Not really

I want adding the following dependency

The best it to use a maven target location instead of a pom dependency

it looks like I still need to manually list all the dependencies with MANIFEST.MF/Require-Bundle

Not really why should it be required?

If you want to build an update-site simply choose to include all dependencies:

https://tycho.eclipseprojects.io/doc/latest/tycho-p2-repository-plugin/assemble-repository-mojo.html#includeAllDependencies

By the way https://github.com/eclipse-tycho/tycho/discussions is more suitable to ask questions.

@vlsi
Copy link

vlsi commented Nov 12, 2023

I indeed missed the discussions. I've moved the question to #3033

If you want to build an update-site simply choose to include all dependencies

I guess I will need an update-site, however, my primary goal is to build a plugin. Does creating update-site help building the plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants