Why does Intellij IDEA say that used properties are unused?

寵の児 提交于 2021-01-28 00:01:46

问题


I have a properties file in my Java maven project. I have one class which loads these properties and stores them as constants.

//Constants.java file has this code.
Properties properties = new Properties(blah...);
String username = properties.getProperty("my.username");
System.out.println(username);

Despite using my.username property and the username variable, Intellij IDEA says that it is unused. Why ? I tried to invalidate caches and restart the IDE, but it did not change anything.

As a result, its hard to find out which properties are actually unused and remove them.

Here is the project structure :

PROJECT1

-> PROJECT2
--> src > main > resources > folder > my.properties
--> pom.xml

-> PROJECT3
--> src > main > java > packagea.b.c > packaged > packagee > Constants.java
--> pom.xml

pom.xml

回答1:


The issue is not reproducible:

If you have the Minimal, Complete, and Verifiable example, please share it so that we can investigate why the it happens in your specific project.

Here is the properly working sample: unused-properties.zip.


To match your multi module Maven project from the description I've created another sample project to illustrate the configuration and the properly working inspection.

Get the sample project here: unused-multimodule-maven.zip.

This project has an aggregate pom.xml in the root directory and 2 modules: app and properties where app depends on properties.

Proof of working screenshot:

Notice that the app module depends on the properties module. This dependency is achieved via the following pom.xml configuration of the app module.

    <dependencies>
        <dependency>
            <groupId>com.jetbrains.support</groupId>
            <artifactId>properties</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>


来源:https://stackoverflow.com/questions/57914753/why-does-intellij-idea-say-that-used-properties-are-unused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!