2

I have three maven projects as three osgi bundles (that is one project is one bundle). And I have three classes - one class in each bundle.

Project/Bundle 1:
class A{}
pom:    

Project/Bundle 2:
class B extends A{}
pom:
 <dependency>
     <groupId>com.company</groupId>
     <artifactId>project1</artifactId>
     <version>1.0.0</version>
     <scope>provided</scope>
</dependency>

Project/Bundle 3
class C extends B{}
pom:
 <dependency>
     <groupId>com.company</groupId>
     <artifactId>project2</artifactId>
     <version>1.0.0</version>
     <scope>provided</scope>
</dependency>

Why when I compile project3 I get exception that class A can't be accessed? The problem is solved only adding project1 as dependency to project 3. But, why?

Pavel_K
  • 10,748
  • 13
  • 73
  • 186

1 Answers1

2

It is because of the provided scope. It breaks the transitive lookup.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thank you for your answer. I changed scope to compile, but I don't see any difference between jar compiled with "provided" scope and jar compiled with "compile" scope. How to explain it? – Pavel_K May 21 '16 at 11:27
  • Did you change both? – Christian Schneider May 21 '16 at 11:36
  • Yes, I chaned for project2 and project3. I mean, that now I don't need dependency to project1 in project3. But I don't see any difference in jar. I thought, that if I set to compile, that for example bundle1 will be inserted in bundle2. – Pavel_K May 21 '16 at 11:56
  • Ah ok. So it solved your problem. The issue is not in the jar but in maven. Maven only follows provided deps on the first level. – Christian Schneider May 21 '16 at 15:14
  • I don't understand when you say "don't see any difference in jar". In the first case, there was no JAR at all because of (valid) compilation errors. When you added the dependency, Maven was able to build a JAR. The difference between a JAR not existing and existing is quite large, isn't it? – Neil Bartlett May 21 '16 at 22:22
  • 1
    @Neil Bartlett When I say about difference I say about the difference between jar built with provided scope (adding project1 as dependency for project3 - I wrote it in my post) and jar built with compile scope (without adding project1 as dependency for project3). As I understand this post http://stackoverflow.com/a/25777709/5057736 with scope compile project1 had to be packaged `inside` bundle3. However, I don't see it. That is what I am asking. – Pavel_K May 22 '16 at 07:13
  • 1
    @Neil Bartlett Please, don't forget to send me message using at symbol. – Pavel_K May 22 '16 at 07:17
  • 1
    @JimJim2000 No, using compile scope dependency does not mean that the bundle should be embedded. The answer you linked to relates to building WAR files, which is irrelevant. – Neil Bartlett May 22 '16 at 08:01
  • @Neil Bartlett Thank you for your explanation. – Pavel_K May 22 '16 at 08:42