Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

java - How to disable pom.xml validation in IntelliJ IDEA

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':

enter image description here

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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: Screenshot of setting Maven Runner Properties

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: Screenshot of removing property from specific build configuration

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...