How to disable pom.xml validation in IntelliJ IDEA

后端 未结 5 1955
感动是毒
感动是毒 2020-12-15 04:23

I\'m using buildnumber-maven-plugin to get Mercurial changeset as project build number:


    org.codehaus.mojo
          


        
相关标签:
5条回答
  • 2020-12-15 04:59

    As it is working fine. I think it would be some cache or may be little bug which has no major effect giving some info. So I want to suggest you some options

    Suggestion-1:

    You can rebuild your project and then check

    Build > Rebuild Project
    

    Suggestion-2:

    You can clear your ide's caches

    1. File -> invalidate caches
    2. Then Restart application

    Suggestion-3:

    Sometimes silly trick may solve the issue.

    1. Right click on the code editor
    2. Hover on Maven and expand
    3. Click on Reimport

    Suggestion-4:

    There are some ways to solve the issue and also discussion what is happening version to version. You can go through

    IntelliJ inspection gives "Cannot resolve symbol" but still compiles code

    Suggestion-5:

    You can make a try Michał Wróbel's blog: Cannot resolve symbol XYZ in IntelliJ although maven builds sources properly

    Suggestion-6:

    You can also disable reading pom.xml on every small changes in IntelliJ Idea: Intellij IDEA and Maven, disable reading pom.xml on every small change, even without a save

    0 讨论(0)
  • 2020-12-15 05:14

    Try File->Settings->Editor->Inspections->uncheck "Maven Model Inspection" and apply.

    0 讨论(0)
  • 2020-12-15 05:22

    The question asks for how to deactivate the verification because of the unfixed IntelliJ bug causing false errors for the syntax "${dynamic.variable}" in dynamic pom.xml variables.

    Instead, here is a workaround for the bug, so the false error notification disappears and the maven still accepts the variable and everyone is happy:

    Change variable syntax in this order (no joke): 1. "${dynamic.variable}" 2. "{dynamic.variable}" 3. "{$dynamic.variable}"

    IntelliJ will now accept it as correct and maven will also parse and accept the dynamic variable without problem. It is obviously an undocumented maven syntax which for some reason has been implemented as the correct and only syntax in IntelliJ IDE.

    I hope this helps everyone, despite it not answering the actually asked question, but eliminates the reason for asking it instead.

    Have fun :)

    0 讨论(0)
  • 2020-12-15 05:24

    Yeah, that looks broken

    Interesting. I've tested this behavior in both IntelliJ IDEA Ultimate 14.1.7 as well as IntelliJ IDEA Community 2016.1.2, and properties that IDEA doesn't know about still show as red even with all Maven inspections turned off. This looks to be a bug (or to put it more charitably, an unimplemented feature) in IDEA, that the error it gives when it can't identify a property isn't controlled by the inspections settings.

    There are a couple related issues in IDEA's bug tracker:

    • IDEA-96358: Maven: cannot resolve environment variables
    • IDEA-100272: Maven: support for implicit properties

    There's also a post on a similar issue on the JetBrains support forum:

    • 'Cannot resolve symbol' in my Maven POM file for @VAR@ property values

    A possible workaround

    There's a workaround listed in both the comments of IDEA-96358 as well as in the support post. You can add a dummy version of your dynamic properties in Settings / Build, Execution, Development / Build Tools / Maven / Runner / Properties, like in this screenshot:

    Putting values in there will let IDEA know about them so it will not highlight them in red. However, I found in my testing that since IDEA was passing the values as properties to Maven, they weren't getting overwritten by the buildnumber-plugin and I was seeing my dummy value instead when I tried to use it. (The only way I tested using it was in a maven-help-plugin evaluate goal, but perhaps it works when using it in other ways?) In order to be able to use the dynamically-set value, in my specific build configuration I unchecked the "Use project settings" box and removed the dummy property, as in this screenshot:

    This is starting to be quite an annoying workaround, as if you have a lot of Maven build configurations and like the ability for them all to default to the same runner settings, you'd now have to duplicate the "real" setup you want in each configuration, and have the default in the project settings dialog just be for the "dummy" values so that IDEA knows that it shouldn't treat referencing that property as an error. This also requires you to run all your Maven commands via build configurations, and not via other means like double-clicking lifecycles in the "Maven Projects" tool window. Though if you have few build configurations, those are the only way you run Maven from within IDEA, and the color red when editing your pom.xml file is annoying you enough, perhaps this workaround is an acceptable tradeoff for you.

    Further steps

    As it appears that IDEA's built-in functionality doesn't really cover dynamically-generated properties, I think the only real way to fix it is to convince JetBrains to do it, unless there's some way to add the functionality in a third-party plugin (which is now very much getting beyond my expertise). I'd suggest either voting for and commenting on one of the tickets in JIRA's tracking system I mentioned, or creating your own if you think your issue is different enough (which it may be). Also, you may want to contact JetBrains support, particularly if you have a paid subscription with them. While I suspect that they have many priorities to work on (as do we all), I also suspect that more people asking for something increases the chance of it moving toward the top of their backlog. Asking nicely for something rarely hurts.

    0 讨论(0)
  • 2020-12-15 05:26

    With respect, none of SkyWalkers solutions worked for me.

    But the following one worked for me:

    Simply add this above the property lines:

    <!--suppress UnresolvedMavenProperty -->
    

    So you'll end up with:

    <!--suppress UnresolvedMavenProperty -->
    <git.version>${git.commit.time}.${git.commit.id.abbrev}</git.version>
    
    0 讨论(0)
提交回复
热议问题