Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Generated not found #95

Closed
sockeqwe opened this issue Dec 17, 2014 · 12 comments
Closed

@Generated not found #95

sockeqwe opened this issue Dec 17, 2014 · 12 comments

Comments

@sockeqwe
Copy link

Hi,
I think it's a problem with my environment (java 1.7.0_51, 64 bit, mac os 10.10), but I'm using Android Studio and tried to setup a simple android sample application with dagger 2 as dependency injection framework.

My compiler can not resolve the @Generated annotation in class path (import javax.annotation.Generated;) which is used in all dagger generated classes.

My gradle build file looks like this:

compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'

Any idea what could be wrong?
Do I have to add the javax annotation dependency to my build.gradle?

@radzio
Copy link

radzio commented Dec 17, 2014

@sockeqwe: just fast fix but did you tried to add this:

compile 'org.glassfish:javax.annotation:10.0-b28'

@sockeqwe
Copy link
Author

jep, that works!
I think this dependecy should be part of the core module dependency, shouldn't it?

Im wondering if I'm the only one who is facing this problem?

@sockeqwe
Copy link
Author

Oh, it seems that it's working fine with provided scope, but I'm not sure why (the dependency is still missing?!?!?).

My problem was, that I have used apt instead of provided. In the apt generated code @Generated can not be resolved. After cleaning the project and using provided everything works. I'm still wondering why it works with provided, because the dependency to @Generated is missing ... I guess it's because @Generated has retention policy source ...

@tbroyer
Copy link

tbroyer commented Dec 17, 2014

javax.annotation.Generated is part of the JDK since at least Java 6, so maybe the problem is that you're using the Android API: square/javapoet#139 (comment)
(disclaimer: I don't do Android development)

That said, you need @Generated to be in your compilation classpath (compile or provided) because it's part of a (generated) source file that will be compiled; not in your processor path (apt) which is about the code that will generate that java source. And because it's an annotation that's not needed at runtime, iff you need to include a dependency to get that annotation in the compilation classpath (btw javax.annotation:javax.annotation-api:1.2 is more recent), then use the provided scope.

@JakeWharton
Copy link

Yep. Android's API jar lacks Generated. You will always need to include an
additional dependency on the glassfish jar for Android projects.
On Dec 17, 2014 2:43 AM, "Thomas Broyer" notifications@github.com wrote:

javax.annotation.Generated is part of the JDK since at least Java 6, so
maybe the problem is that you're using the Android API: square/javapoet#139
(comment)
square/javapoet#139 (comment)
(disclaimer: I don't do Android development)

That said, you need @generated to be in your compilation classpath (
compile or provided) because it's part of a (generated) source file that
will be compiled; not in your processor path (apt) which is about the
code that will generate that java source. And because it's an annotation
that's not needed at runtime, iff you need to include a dependency to get
that annotation in the compilation classpath (btw
javax.annotation:javax.annotation-api:1.2 is more recent), then use the
provided scope.


Reply to this email directly or view it on GitHub
#95 (comment).

@cgruber
Copy link

cgruber commented Mar 26, 2015

this is a local project configuration matter. If you're targetting a JVM that doesnt' have it, you need to add it, per the instructions above.

@cgruber cgruber closed this as completed Mar 26, 2015
@mttkay
Copy link

mttkay commented May 15, 2015

Why Glassfish? Why not the official Java annotations from Oracle?

https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.pom

@svenjacobs
Copy link

I think the correct dependency which should be added is javax.annotation:jsr250-api:1.0. At least this one only contains the annotations from JSR 250.

I added this to my Android Gradle project:

provided 'javax.annotation:jsr250-api:1.0'

@ronshapiro
Copy link

I just submitted some code (and will be linked to this issue in the next MOE sync) that omits @Generated and instead includes a comment about the generation step if javax.annotation.Generated is not on the compile-time classpath.

@ronshapiro ronshapiro reopened this Dec 10, 2015
ronshapiro added a commit that referenced this issue Dec 30, 2015
…time classpath.

See Github Issue #95 for users that get stuck when compiling for Android and their build fails because the annotation is not present.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=109933503
cgruber pushed a commit that referenced this issue Dec 30, 2015
*** Reason for rollback ***

Lots of down-stream compilation failures in continuous integration.

*** Original change description ***

Only omit @generated if javax.annotation.Generated is on the compile-time classpath.

See Github Issue #95 for users that get stuck when compiling for Android and their build fails because the annotation is not present.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=109941410
ronshapiro added a commit that referenced this issue Dec 30, 2015
…ime classpath.

See Github Issue #95 for users that get stuck when compiling for Android and their build fails because the annotation is not present.

***

Rollforward of a prior commit.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=110258324
@ronshapiro
Copy link

The commit which omits @generated is now synced and should be in a 2.1-SNAPSHOT

@rafnogueira
Copy link

Probably this happened because the system JDK_HOME is more upgraded then the JDK that comes with Android Studio

@RiteshAdulkar
Copy link

I have installed sdkman more here: https://sdkman.io/usage#installdefault, downgraded java version from 11 to 8 and this error did go away. That way it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants