Error with CDI Events

I have this odd issue w/ IntelliJ (and I'm a new user, so double the fun).

Anyways, I'm injecting events left and right

private Event<Foo> fooEvent;

however, I get errors in the IDE that it can't find symbol. Is this an internally reserved word?

Comment actions Permalink

Hello John,

Wlecome to the IDEA community.

Your issue is usually a sign that the library containing the desired element is not in the classpath. You'll want to verify the library is present in your IDEA project's configuration. You can look in the "Libraries" node in the project tool window to see if the required library is present. You can also look in File > Project Structure > Modules > {module name} > Dependency Tab to verify the library is present. If it is missing, and you configured your project manually, you need to add the library. If you IDEA configured it for you via a maven or gradle import, you may just need to force a reimport so IDEA syncs up properly (assuming the dependency is properly declared in your POM or the gradle equivalent.)

If the configuration looks good and the library is present, it is possible the chaches and/or indexes for the project are corrupt, so IDEA does not "see" the dependency. While it does not happen often, it does happen. To fix, go to File > Invalidate Caches and restart IDEA. When you open the project, IDEA will reindex it (Progress is shown on the bottom status bar near the middle right). Depending on the size of the project (and your CPU) this can take anywhere from sub-second to a minute or so. Once the indexing is complete, the error should go away. If not, then you're back to it being a configuration problem.

Comment actions Permalink

Hi Mark,

Thanks for the reply.

My project is maven based.  The class is provided in the javax.enterprise:cdi-api JAR. It is shown correctly in the library list.

I tried clearing my cache and restarting, but the error remains.



Also of note is that if I hit CTRL + SHIFT + N and type in javax.enterprise.event.Event, the class does not show.

Message was edited by: John Ament

Comment actions Permalink

Strange.... It sounds likes IDEA is not resolving it correctly. Can you go into File > Project Structure > Project Settings > Modules > [Module Name] > Dependencies Tab. Find the library in the list of dependencies and make sure the library shows with the correct scope. See the screen shot below.  If it is not, double check it's scope in the POM.

The other things I can recommend are 1) double check that the jar (in your local repo) is not corrupt. 2) In the maven tool window, execute a "reimport all maven projects" . Execute it two or three times (waiting for it to finish each time). Once in a blue moon (like twice in the past 4or 5 years) I've seen a case where you have to do that to get IDEA to properly pull in a jar.

If none of that works, try deleting the jar from your local repo, clear IDEA's caches and restart, and then reimport the maven project. This is not something you would normally have to do... but if everything is configured correctly, the only thing I can think of is that there is just something wrong with that JAR, or something wrong with IDEA's indexing of it.

Let us know how it goes. I'm very curious at this point. Typical using maven in IDEA is as smooth as silk.


Comment actions Permalink

Interesting.  IntelliJ definitely has the wrong scope for the JAR.

My dependency is this in the pom.xml


which includes this scope


However, IntelliJ thinks it was test scope.  Is it possible IntelliJ is misunderstanding the scope somehow?

Comment actions Permalink

Looks like it might be this Bug:  -- Although in that bug the poster is saying it is a runtime issue, not a compile time issue.  It's interesting as I have some 'provided' scope dependencies in a number of my projects and have not run into this issue. I'd be curious what the factor is that triggers it.

As a workaround, you should be able to change the scope in IDEA's dependency settings. But it will (I'm pretty sure) get reverted back each time you import the Maven project. Who knows, maybe once you change it, ti will keep.

Comment actions Permalink


Sorry for the late reply, but I think I found the cause.  In my maven project, one of my first dependencies was a test scope for something that provides this package.  Then later on I had a provided scope of the same package.  Maven correctly reflects this as having provided scope (since the impl is the test scope).  It looks like intellij is seeing the first scope as test and saying "yes, you can use that in your maven project if it's src\test\java" which mine was an impl, causing this.

Switching the order in the pom worked.  Is there a way that the referenced ticket could be updated to reflect this info?



Please sign in to leave a comment.