如何在IntelliJ IDEA中禁用pom.xml验证 [英] How to disable pom.xml validation in IntelliJ IDEA

查看:3346
本文介绍了如何在IntelliJ IDEA中禁用pom.xml验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用



此外,模块根目录和受影响的 pom.xml 文件在项目工具窗口中以红色下划线标出。



我试过所有提供的 Alt + 在设置中输入选项和Maven配置;什么都没有帮助。



一切都建立并且工作正常,我只是想摆脱IDE中显示的恼人错误。有什么建议吗?



IDE和环境:

  IntelliJ IDEA 2016.1。 2 
Build#IC-145.972,建于2016年5月14日
JRE:1.8.0_65-b17 amd64
JVM:Oracle公司的Java HotSpot(TM)64位服务器VM


解决方案

是的,看起来很破碎



有趣。我已经在IntelliJ IDEA Ultimate 14.1.7和IntelliJ IDEA Community 2016.1.2中测试了这种行为,即使所有Maven检查都关闭,IDEA不知道的属性仍显示为红色。这看起来是IDEA中的一个错误(或者说它更加慈善,一个未实现的功能),当它无法识别属性时它给出的错误不受检查设置的控制。



IDEA的错误跟踪器中存在一些相关问题:






  • 将值放在那里让IDEA了解它们,这样它就不会用红色突出显示它们。但是,我在测试中发现,由于IDEA将值作为属性传递给Maven,因此它们没有被buildnumber-plugin覆盖,而是当我尝试使用它时,我看到了我的虚拟值。 (我测试使用它的唯一方法是在maven-help-plugin评估目标中,但也许在其他方面使用它时可行吗?)为了能够使用动态设置值,在我的特定构建配置中取消选中使用项目设置框并删除虚拟属性,如此屏幕截图所示:



    这是开始是一个非常烦人的解决方法,好像你有很多Maven构建配置,并且喜欢它们都默认为相同的跑步者设置的能力,你现在必须在每个配置中复制你想要的真实设置,并且在项目设置对话框中具有默认值,只是为了虚拟值,以便IDEA知道它不应该将引用该属性视为错误。这还要求您通过构建配置运行所有Maven命令,而不是通过双击Maven Projects工具窗口中的生命周期等其他方法。虽然如果你有很少的构建配置,那么这是你在IDEA中运行Maven的唯一方法,编辑你的pom.xml文件时的颜色为红色很烦人,也许这种解决方法对你来说是可以接受的权衡。



    进一步的步骤



    由于IDEA的内置功能似乎并未真正涵盖动态生成的属性,我认为只有真正的方法来解决它是说服JetBrains这样做,除非有一些方法在第三方插件中添加功能(现在它已经超出了我的专业知识)。我建议投票和评论我提到的JIRA跟踪系统中的一张票,或者如果你认为你的问题不同(可能是这样)就创建你自己的票。此外,您可能希望联系JetBrains支持,特别是如果您有付费订阅。虽然我怀疑他们有很多优先事项要做(我们都是这样),但我也怀疑更多的人要求某些事情会增加他们积压到积压的可能性。好好地问一些很少疼的东西。


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

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <phase>initialize</phase>
                <goals>
                    <goal>hgchangeset</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    Then I use ${changeSet} property to set build.number property in the same pom.xml:

    <build.number>${changeSet}</build.number>
    

    However, IntelliJ IDEA complains that it Cannot resolve symbol 'changeSet':

    Also, the module root and the affected pom.xml files are underlined in red in the Project tool window.

    I tried all of the offered Alt+Enter options and Maven configurations in the Settings; nothing helped.

    Everything builds and works fine, I just want to get rid of the annoying error displayed in the IDE. Any suggestion?

    IDE and environment:

    IntelliJ IDEA 2016.1.2
    Build #IC-145.972, built on May 14, 2016
    JRE: 1.8.0_65-b17 amd64
    JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
    

    解决方案

    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:

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

    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.

    这篇关于如何在IntelliJ IDEA中禁用pom.xml验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆