Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355947

Summary: Optional dependencies broken in recent Tycho build
Product: z_Archived Reporter: Markus Kuppe <bugs.eclipse.org>
Component: TychoAssignee: Project Inbox <tycho-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: igor, kai
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Markus Kuppe CLA 2011-08-26 09:13:42 EDT
With commit https://github.com/sonatype/sonatype-tycho/commit/048054f214925d79ad376f7ec452893d424d7e19 Tycho does not resolve optional dependencies anymore, which causes builds to fail.

[INFO] --- tycho-compiler-plugin:0.13.0-SNAPSHOT:compile (default-compile) @ org.lamport.tlatools ---
[INFO] Using compile source roots from build.properties
[INFO] Compiling 385 source files to /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/target/classes
----------
1. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/util/SimpleFilenameToStreamTest.java (at line 5)
	import junit.framework.TestCase;
	       ^^^^^
The import junit cannot be resolved
----------
2. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/util/SimpleFilenameToStreamTest.java (at line 7)
	public class SimpleFilenameToStreamTest extends TestCase {
	                                                ^^^^^^^^
TestCase cannot be resolved to a type
----------
3. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/util/SimpleFilenameToStreamTest.java (at line 16)
	assertNotNull(file);
	^^^^^^^^^^^^^
The method assertNotNull(File) is undefined for the type SimpleFilenameToStreamTest
----------
4. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/util/SimpleFilenameToStreamTest.java (at line 17)
	assertTrue(file.getAbsolutePath() + " does not exist!", file.exists());
	^^^^^^^^^^
The method assertTrue(String, boolean) is undefined for the type SimpleFilenameToStreamTest
----------
----------
5. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/util/ByteUtilsTest.java (at line 11)
	import junit.framework.TestCase;
	       ^^^^^
The import junit cannot be resolved
----------
6. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/util/ByteUtilsTest.java (at line 19)
	public class ByteUtilsTest extends TestCase
	                                   ^^^^^^^^
TestCase cannot be resolved to a type
----------
7. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/util/ByteUtilsTest.java (at line 37)
	super.setUp();
	^^^^^
TestCase cannot be resolved to a type
----------
----------
8. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/tool/distributed/TLCWorkerSmartProxyTest.java (at line 9)
	import junit.framework.TestCase;
	       ^^^^^
The import junit cannot be resolved
----------
9. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/tool/distributed/TLCWorkerSmartProxyTest.java (at line 11)
	public class TLCWorkerSmartProxyTest extends TestCase {
	                                             ^^^^^^^^
TestCase cannot be resolved to a type
----------
10. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/tool/distributed/TLCWorkerSmartProxyTest.java (at line 19)
	assertTrue(doTest(calculationDuration, new DummyTLCState[ONE]) > 0);
	^^^^^^^^^^
The method assertTrue(boolean) is undefined for the type TLCWorkerSmartProxyTest
----------
11. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/tool/distributed/TLCWorkerSmartProxyTest.java (at line 24)
	assertTrue(doTest(calculationDuration, new DummyTLCState[ONE]) > 0);
	^^^^^^^^^^
The method assertTrue(boolean) is undefined for the type TLCWorkerSmartProxyTest
----------
12. ERROR in /usr/local/src/tla/tla/trunk/tla2-inria/tlatools/test/tlc2/tool/distributed/TLCWorkerSmartProxyTest.java (at line 29)
	assertTrue(doTest(calculationDuration, new DummyTLCState[ONE]) > 0);
	^^^^^^^^^^
...

Manifest.mf:

Require-Bundle: org.aspectj.runtime;bundle-version="1.6.0";resolution:=optional,
 org.junit;bundle-version="3.8.0";resolution:=optional
Comment 1 Igor Fedorenko CLA 2011-08-26 10:26:57 EDT
Can you confirm the problem was not present at https://github.com/sonatype/sonatype-tycho/commit/4393caf41c9e1968d2711b97fda4cdea021814d2 ?

In case, jars.extra.classpath can be used to force compile-only dependencies.
Comment 2 Markus Kuppe CLA 2011-08-26 10:29:57 EDT
(In reply to comment #1)
> Can you confirm the problem was not present at
> https://github.com/sonatype/sonatype-tycho/commit/4393caf41c9e1968d2711b97fda4cdea021814d2
> ?

I will check, but it will take a while.

> In case, jars.extra.classpath can be used to force compile-only dependencies.

In pom.xml?
Comment 3 Igor Fedorenko CLA 2011-08-26 10:44:25 EDT
(In reply to comment #2)
> 
> > In case, jars.extra.classpath can be used to force compile-only dependencies.
> 
> In pom.xml?

No, in build.properties http://help.eclipse.org/indigo/topic/org.eclipse.pde.doc.user/reference/pde_feature_generating_build.htm
Comment 4 Kai Kreuzer CLA 2011-08-26 17:09:08 EDT
> > Can you confirm the problem was not present at
> > https://github.com/sonatype/sonatype-tycho/commit/4393caf41c9e1968d2711b97fda4cdea021814d2
> > ?

I can confirm, my build was still working with the 0.13.0-SNAPSHOT from August 25.

The problem seems to be that Equinox p2 Juno treats optional dependencies non-greedy now, on indigo it was by default a greedy behaviour (see bug 247099). Unfortunately, this change now also impacts the scope during compile time, which was most likely not intended.

I have created a very simple project to easily reproduce the problem: https://github.com/openhab/tycho-testing

Note that you can work around it by defining the optional dependency as greedy. This is done by specifying "resolution:=optional;x-installation:=greedy" in the manifest for the dependency in question.

Hope this helps!
Kai
Comment 5 Tobias Oberlies CLA 2011-08-30 07:39:38 EDT
(In reply to comment #4)
> The problem seems to be that Equinox p2 Juno treats optional dependencies
> non-greedy now, on indigo it was by default a greedy behaviour (see bug 247099).
> Unfortunately, this change now also impacts the scope during compile time, which
> was most likely not intended.
This is correct. Greedy should only affect installation, but not compilation. Unfortunately this is an open issue in Tycho: bug 351842.

> Note that you can work around it by defining the optional dependency as greedy.
> This is done by specifying "resolution:=optional;x-installation:=greedy" in the
> manifest for the dependency in question.
This is a very bad idea, because this has an impact on your users: if the optionally required bundle is common (e.g. part of Indigo), it will be installed whenever your users install your bundle. If it is however truely optional, you should give your users the choice to install it by creating two features: one with just your bundle(s) and one with your bundles and requirements to the optional stuff.

*** This bug has been marked as a duplicate of bug 351842 ***