Derek M
Derek M

Reputation: 53

'cannot resolve symbol' with @ symbols in pom.xml in IntelliJ

I'm getting an error in a Maven pom.xml file when I have a property with 2 @ symbols with some characters between. The only message is

cannot resolve symbol 'symbol'.

This does not cause errors building or running the application, but it does cause red underlines on the project window (using IntelliJ IDEA 14).

I've tried to disable Inspections for XML and Maven but the issue remains.

If I close IntelliJ and reopen, as long as I don't reopen the pom.xml file, the error doesn't come up.

I can't find any references to what 2 @ symbols might mean in Maven or XML so I'm inclined to think it's an IntelliJ specific thing.

What causes this error and how can I fix it (other than changing the property value or never opening the file)?

screenshot

Upvotes: 3

Views: 3341

Answers (1)

krevelen
krevelen

Reputation: 391

TL;DR@@${at}${at} (or: @{}${at}{} for failsafe argLine in IDEA)

Although slightly different, my case (involving IntelliJ IDEA v2017.3.5) was solved following a work-around from this answer by Mike, that is, to define the @ symbol as a separate property, e.g. <at>@</at>, i.e. in your test-case: <at>@</at> and <myproperty>${at}hello!${at}</myproperty>.

This solution seems to work at least for the argLine option as used in both maven-surefire-plugin (v2.21.0) and maven-failsafe-plugin (v2.21.0), where I needed to include JVM arguments for a code coverage agent of the jacoco-maven-plugin (v0.8.0). The original property (with compile-time value ${..}) must be read at run-time using @{..} (see the failsafe docs), a term which does not validate in IntelliJ. So for my case, we have: ${..}@{..}${at}{..}

<project ...>
    :
    <properties>
        <at>@</at>
        :
        <argLine>...</argLine>
        <my.jacoco.args/>
    </properties>
    :
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>my.jacoco.args</propertyName>
                            :
                        </configuration>
                    </execution>
                    :
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.21.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <argLine>${at}{my.jacoco.args} ${at}{argLine}</argLine>
                            :
                        </configuration>
                    </execution>
                    :
                </executions>
            </plugin>
            :
        </plugins>
    </build>
</project>

Upvotes: 1

Related Questions