Error: package javax.annotation does not exist after upgrade to lombok 1.16.2
Asked Answered
F

3

58

My android project builds fine with lombok 1.16.0, but once I change my dependency to target 1.16.2, I get the following error everywhere I'm using a lombok annotation:

Error:(20, 1) error: package javax.annotation does not exist

The Android SDK does not include all javax packages. What I'm wondering is if this is a bug in 1.16.2 or do I now have to add a dependency to javax.annotation?

Note: This is in Android Studio with Lombok plugin 0.8.8

Fredel answered 11/2, 2015 at 22:16 Comment(0)
A
98

You can disable the generation of javax.annotation.Generated by putting the following line in a lombok.config file in one of the top directories of your project:

lombok.addGeneratedAnnotation = false

See the configuration documentation for more information.

Disclosure: I am a Lombok Developer.

Acis answered 12/2, 2015 at 9:1 Comment(5)
Lombok config doesn't exist or work with Android Studio currently right?Bracer
@RoelSpilker You´re a lifesaver man. Thanks a lot for Lombok, it´s a must-have in every good developer toolkit! ;-)Custodial
@serkan lombok.config works fine with Android Studio it seemsMarrero
@serkan you can create lombok.config file in android studio and then put this line.Yodle
lombok.config file does not exist, and creating it did not fix the issue.Nathalienathan
C
26

If you're facing same issue in Android Studio using gradle - add following line to build.gradle:

provided 'org.glassfish:javax.annotation:10.0-b28'
Clematis answered 2/4, 2015 at 8:3 Comment(2)
Why 10.0-b28 as opposed to 3.1.1 or 3.2-b06? 10.x appears to be 3 years older than the other versions.Outstretch
Using a GlassFish dependency doesn't seem right. I prefer compile 'javax.annotation:jsr250-api:1.0 per this answer. Though, jsr250-api is rather old (2007). Note: I am using Dagger 2, not Lombok.Underlay
R
-2

The right answer for android development today is to use a version of dagger which is greater than 2.1 (because of the fix mentioned by @tomrozb is integrated in 2.1)

Radu answered 17/8, 2016 at 11:24 Comment(1)
This is a lombok issue, not a dagger issueSpelt

© 2022 - 2024 — McMap. All rights reserved.