Maven package works but Intellij's build fails

75,460

Solution 1

I've found out that my .iml file and pom were conflicting and causing the issue.

Solution 2

I know this is late but executing mvn idea:idea solves the issue.

The command re-generates the crucial IntelliJ IDEA files: ipr, iml, and iws, and thus re-align them with your pom.xml.

Documentation: https://maven.apache.org/plugins/maven-idea-plugin

The plugin is retired but still (as of 05.06.2021) works like magic :)

Solution 3

Try to delete all .iml and your POM. Then copy and paste your POM again to your project and re-open and re-import it.

Solution 4

Maven ReImport worked for me like below...

enter image description here

Solution 5

Adding some more tips since this is the first thing that came up in the search when I was having similar problems (project builds in mvn, not in IntelliJ), in case it might help someone else.

When I had this it was a different fix on Windows and Mac.

On Mac, I went into ItellijIDEA / Preferences / Build, Execution, Deployment / Build Tools / Maven / Maven Home Directory and set it to use my separately installed Maven rather than the bundled Maven. All the build problems went away.

On Windows, I was seeing exceptions in the idea.log related to SSL and my project tree had only Java under the External Libraries branch. From looking at other sites it sounds like IntelliJ uses its own private JDK instead of the system one (even though in my case I already had the exact same JDK version installed). My system JDK has certs installed in the keystore for the corporate Nexus server that the IntelliJ private JDK didn't have, so exceptions were being thrown when it tried to get files from Nexus. For this the solution was to quit IntelliJ, set an environment variable called IDEA_JDK to point to the JDK I already had installed that had the proper certs and restart IntelliJ. All the build problems went away.

Share:
75,460
Yarin Miran
Author by

Yarin Miran

Updated on June 05, 2021

Comments

  • Yarin Miran
    Yarin Miran almost 3 years

    I have a JDK 1.7 project with a maven dependency to a local jar in my maven repo.

    I'm unable to build the project using Intellij, with the errors that a symbol cannot be found (the symbol is a class importing packages from the local jar)

    But I can successfully build the project using 'mvn package'.

    I've spent so much time looking for solutions, things I've already done:

    • Invalidated cache
    • 'mvn clean install' the local jar dependecy
    • Marked to 'autoload snapshots' in Intellij's maven configuration
    • Reimpoted maven in Intellij
    • Syncornized

    This error happend to my couple of times before, but usually just closing the Intellij and /or doing the 'mvn clean install' did the trick.

    Please help.

  • chalimartines
    chalimartines over 10 years
    I have similar problem. I have configuration with build date plugin. This plugin requires buildDate property with this value "${maven.build.timestamp}". IntelliJ has problem with parsing this pom and iml file isn't properly synchronised with pom. When I comment property buildDate synchronisation works fine.
  • Breno Salgado
    Breno Salgado over 10 years
    any tips on how to fix this? I'd just like to Intellij to work, it seems Netbeans runs any project no matter what... this is a complete productivity destroyer :( ...
  • SonarJetLens
    SonarJetLens almost 10 years
    I don't know if your fix was the same but I had to quit and reload the project to force IntelliJ to update it's IML file (it hadn't refreshed it from pom.xml as I'd added some new dependencies)
  • Zveratko
    Zveratko about 9 years
    Maybe just try to "re-import all" in Maven Project view, before deleting anything
  • Daniel de Zwaan
    Daniel de Zwaan almost 8 years
    I've had to delete the .iml too, re-import maven didn't fix it.
  • tabalin
    tabalin about 7 years
    @masoodg, thank you so much! you saved my day! Just re-import didn't help. Followed your instructions, and it works like a charm.
  • Gregor
    Gregor about 7 years
    same issue on Linux with latest IntelliJ 2016.3.5 - first it worked, then after some POM changes it got ouf of sync, and only switching the Maven impl helped, so it could also be that just switching Maven triggers an update in IntelliJ that causes the project to be in sync again...
  • RDM
    RDM over 6 years
    This should be the accepted answer, as it offers an actual solution, not just the reason why it fails. All my updoots!
  • João Matos
    João Matos over 6 years
    The 'how' is quite more useful than the 'why'. Please add some details on how you fixed this issue.
  • koppor
    koppor over 6 years
    I closed IntelliJ. Then, I deleted C:\Users\USERNAME\.IntelliJIdea2017.2\system. Afterwards, I did a git clean -xdf in the source directory to remove all non-versioned files, and imported the project again. Works like a charm now.
  • Sean
    Sean over 6 years
    mvn idea:idea hasn't been kept up to date, and is not maintained by jetbrains
  • Fabio Filippi
    Fabio Filippi almost 6 years
    I had to re run mvn install after that
  • Bikas Katwal
    Bikas Katwal over 5 years
    Just delete the .iml file of the affected module the and then right click pom.xml, under maven options select unignore project/module to re create .iml file for that module
  • sushilshimpi
    sushilshimpi over 5 years
    If you have installed maven using homebrew, setting maven home directory correctly (for example) /usr/local/Cellar/maven/3.5.4/libexec resolves this issue
  • Duc Tran
    Duc Tran over 5 years
    After that just rebuild the project. Thank you.
  • Martin Bamford
    Martin Bamford over 5 years
    You have saved me from despair. I'd like to kiss you
  • Maxsteel
    Maxsteel about 5 years
    I can't believe I spent so much time trying to fix this. This sorcery just worked! Thank you.
  • craastad
    craastad about 5 years
    Worked for me, deleted .idea and .i* files and reimported the project and it was fine.
  • Lokesh Pandey
    Lokesh Pandey almost 5 years
    I know I am late but can you tell me what mvn idea:idea does ?
  • Ram Ghadiyaram
    Ram Ghadiyaram over 4 years
  • theferrit32
    theferrit32 over 4 years
    Closing Intellij, deleting the *.iml, *.ipr, and *.iws files from the project root directory, then reopening Intellij fixed it for me
  • KansaiRobot
    KansaiRobot over 4 years
    mvn idea:idea can not connect to the repo :(
  • RBz
    RBz almost 4 years
    Why can't intellij just do this alone after all these years. I still need to run this command every single time I import a new project! SMH
  • AGan
    AGan over 3 years
    IntelliJ IDEA Ultimate 2020.3 has "Reload Project" and that worked.
  • Nom1fan
    Nom1fan over 3 years
    Wow ! Still works in 2020... Honestly first time I experienced this after many years of software engineering but good to know ! Was going crazy over this issue for the past 35 min.
  • c.sankhala
    c.sankhala about 3 years
    You are good. This solve my issue. thanks
  • John Vinopal
    John Vinopal about 3 years
    Even in 2021, the only thing that works. No wonder people use npm.
  • Honza Zidek
    Honza Zidek almost 3 years
    YarinMiran Please consider rather accepting @RahulJha's answer, it's the most upvoted and it tells how to fix it very fast and effectively.
  • PAA
    PAA almost 3 years
    What if I have gradle setup with me?
  • Shabbir Essaji
    Shabbir Essaji almost 3 years
    Made my day... Why does this happen though?
  • dasunse
    dasunse over 2 years
    Waw. Great. delete .iml worked for me.
  • Rips
    Rips over 2 years
    I am on on intellij 2021.1.3 and this still works like magic
  • HienaKill
    HienaKill about 2 years
    Still works in 2022. I'm using IntelliJ IDEA 2021.3.3 (Ultimate Edition) Thx!
  • Gunjan Shah
    Gunjan Shah almost 2 years
    idea:idea plugin is no longer available now. I tried with maven v3.0 and v3.8. It did not work. I am getting error " No plugin found for prefix 'idea' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the reposito ries "