Bug 66299 - Cannot find annotation method 'value()' in type 'aQute.bnd.annotation.spi.ServiceConsumer' with Tomcat
Summary: Cannot find annotation method 'value()' in type 'aQute.bnd.annotation.spi.Ser...
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 10
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 10.1.0
Hardware: PC All
: P2 normal (vote)
Target Milestone: ------
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-09 16:08 UTC by Garret Wilson
Modified: 2022-10-11 16:47 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson 2022-10-09 16:08:22 UTC
I have a Java 11 project embedding Tomcat:

```xml
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>9.0.50</version>
</dependency>
```

The Tomcat-specific code is in a subproject with only two classes. When I compile using Maven 3.8.6 and Java 17 using `-Xlint:all`, I see the following warning for that subproject:

> [WARNING] Cannot find annotation method 'value()' in type
> 'aQute.bnd.annotation.spi.ServiceConsumer':
> class file for aQute.bnd.annotation.spi.ServiceConsumer not found

Doing a bit of searching brings up similar (but not exact) things, such as [Lombok Issue #2145](https://github.com/projectlombok/lombok/issues/2145), which hints that I may need to add some sort of extra dependency such as `biz.aQute.bnd:bndlib` or `org.osgi:osgi.annotation`.

But I've tried this and and I still get the warning:

```xml
<dependency>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>bndlib</artifactId>
  <version>2.4.0</version>
</dependency>
```

I also tried this; no difference:

```xml
<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>osgi.annotation</artifactId>
  <version>7.0.0</version>
</dependency>
```
Where is this error coming from, and what does it mean? I don't have any `@ServiceConsumer` annotation in my source code, and I couldn't find any in the Tomcat classes I'm extending, either. Shouldn't the `org.apache.tomcat.embed:tomcat-embed-core` dependency contain everything I need (either in the artifact or via a transitive dependency) just to build a project that references the Tomcat classes? What is missing here?

I also [asked on Stack Overflow](https://stackoverflow.com/q/74000505). No answers so far.
Comment 1 Mark Thomas 2022-10-09 18:50:24 UTC
Bugzilla is not a support forum. This question belongs on the users mailing list.

https://tomcat.apache.org/lists.html
Comment 2 Garret Wilson 2022-10-09 19:37:12 UTC
Well I think the bug will wind up being that Tomcat is not including some needed library in its published artifacts. But we shall see. I'll ask on the mailing list and reopen this ticket if that turns out to be the case.
Comment 3 Garret Wilson 2022-10-11 15:57:52 UTC
I'm reopening this ticket now that the cause is better understood and a simple fix is available. You may still decide not to address this, and that's OK because I have a workaround, but in my opinion the appropriate resolution would not be `INVALID` but rather `WONTFIX`.

In any case I wanted to at least provide a further explanation for completeness and to help anyone else who is looking for the answer in the future.

Summarizing our discussion on the list, Tomcat has a primary Ant-based build workflow which uses the bnd annotation `aQute.bnd.annotation.spi.ServiceConsumer` (which in turn uses the OSGi class `org.osgi.annotation.bundle.Requirement`) to generate JPMS and OSGi metadata. These classes aren't needed in any secondary builds (i.e. using Maven with the embedded Tomcat dependency), but `javac` with linting doesn't like it if these annotation classes are missing.

This can be solved easily enough if Tomcat were to include the following in its POM(s) (versions relevant for Tomcat 10.1.0 shown here):

```xml
<dependency>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>biz.aQute.bnd.annotation</artifactId>
  <version>6.3.1</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>osgi.annotation</artifactId>
  <version>8.1.0</version>
  <scope>provided</scope>
</dependency>
```

Developers can prevent the warning by including those same dependency declarations in their own POMs. The `provided` scope informs Maven that these dependencies should not be included in any resulting JARs in the secondary build.

Even if you decide to close this ticket again, thanks for the discussion on the list and explaining what was causing this. That helped me find a workaround.
Comment 4 Mark Thomas 2022-10-11 16:47:47 UTC
The additional dependency is only required to silence a warning if compiling with -Xlint:all

Making the proposed change to the pom would require every user compiling against this library to download the additional JAR(s). Give that the tomcat-embed-core JAR is downloaded millions of times per month and we only have a single bug report about the warning, it is not appropriate to require every user to download the additional JAR(s) to silence the warning for one user.