eclipse-tycho / tycho

Tycho project repository (tycho)
https://tycho.eclipseprojects.io
Eclipse Public License 2.0
170 stars 189 forks source link

Tycho 4.0.5 cannot find dependency of fragment #3441

Open Phillipus opened 9 months ago

Phillipus commented 9 months ago

I have:

Plugin com.archimatetool.editor Plugin com.archimatetool.canvas - dependent on com.archimatetool.editor

Fragment com.archimatetool.editor.tests- host is com.archimatetool.editor Fragment com.archimatetool.canvas.tests - host is com.archimatetool.canvas

Because some tests in com.archimatetool.canvas.tests extend tests in com.archimatetool.editor.tests there is an additional entry in the com.archimatetool.canvas.tests build.properties file:

extra.. = platform:/fragment/com.archimatetool.editor.tests

(I found the advice to do that here)

When I run the tests in the fragments using Tycho 4.0.5 I now get the error "Missing requirement: com.archimatetool.canvas.tests 4.0.0 requires 'org.eclipse.equinox.p2.iu; com.archimatetool.editor.tests 0.0.0' but it could not be found"

This is working with Tycho 4.0.4.

Did anything change in 4.0.5 that might affect how these are being resolved?

laeubi commented 9 months ago

Did anything change in 4.0.5 that might affect how these are being resolved?

I have no clue, we changed the way filters are applied to be more generic so maybe the requirement simply don't match the environment, but the setup seems strange here and I did not found any reference to extra.. in any tests in Tycho itself so there is a good chance this is some kind of hidden feature no one is really aware of (the mentioned stack overflow is 10 years old!)

So best chance is provide an integration-test to demonstrate the issue and we can probably take a look here.

Phillipus commented 9 months ago

The issue is that Fragment A has a dependency on Fragment B but Tycho doesn't resolve Fragment B because all the package names in Fragment A are the same as Fragment A's host plug-in and it resolves the host plug-in instead of the Fragment. So I've added an Import-Package: packageName statement to Fragment A where packageName is unique to Fragment B. Tycho can now resolve Fragment B.

As for the extra.. line, as you say that doesn't seem to be documented anywhere and that reference to it is very old.

Phillipus commented 9 months ago

As for the extra.. line, as you say that doesn't seem to be documented

Actually it is documented:

extra. - extra classpaths used to perform automated build. Classpath can either be relative paths, or platform urls referring to plug-ins and fragments of your development environment (e.g. ../someplugin/xyz.jar, platform:/plugins/org.apache.ant/ant.jar). Platform urls are recommended over relative paths;

https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Freference%2Fpde_feature_generating_build.htm

So I don't know if this is something that Tycho should still support? It did in 4.0.4.

laeubi commented 9 months ago

@Phillipus yes it is documented for pde build and Tycho try to support as much as possible but it seems there is no test for it --> it may break anytime :-\

So if there is demand for that feature a test would be required to make sure

  1. how it can be used
  2. that it works
  3. that it does not break in the future
Phillipus commented 9 months ago

I attempted a basic test consisting of two plug-ins and two fragments with one fragment dependent on the other and using the extra.. statement. It passed on Tycho 4.0.5. It was only when I introduced JUnit and the fragment classes were converted to JUnit tests that it didn't pass on Tycho 4.0.5. Therefore it's not straightforward so I'm going to leave it for now and see if anyone else comes across the problem.

Phillipus commented 9 months ago

Actually Tycho 4.0.5 is resolving the extra.. = platform:/fragment line in build.properties but it depends upon the order of declaration of modules in the pom.xml.

Suppose we have two fragments, org.foo.package1 and org.foo.package2. If org.foo.package2 has a extra.. = platform:/fragment/org.foo.package1 declaration then the module order in the pom has to be:

<modules>
   <module>org.foo.package1</module>
   <module>org.foo.package2</module>
</modules>

In my own case I just re-arranged the order of modules in the pom and it works again.

But surely the order of modules should not matter?

laeubi commented 9 months ago

@Phillipus then it seems we need to make sure it is used as a requirement in the resolving stage, would you mind to create a test that shows the wrong ordering issue?

Phillipus commented 9 months ago

I made a simple test with 2 plug-ins, 2 fragments and one pom.xml and I can't reproduce it with that simple example. My real life use case is more complicated with more than one pm, tests, and profiles.

Phillipus commented 9 months ago

I've finally created a reproducer, attached.

It involves extending a class from a fragment in another class that contains unit tests. There's a .mvn/maven.config file with Tycho version set to 4.0.5 where the build fails. If this is set to 4.0.4 the build is successful.

Note - the comment above about the order of module declaration doesn't apply to this example.

Could someone try the attached project and see if they get the same result, or maybe I missed something?

test.zip