为什么Intellij IDEA会说使用的属性未使用? [英] Why does Intellij IDEA say that used properties are unused?

查看:264
本文介绍了为什么Intellij IDEA会说使用的属性未使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java maven项目中有一个属性文件.我有一类可以加载这些属性并将其存储为常量.

 //Constants.java文件具有此代码.属性properties =新属性(blah ...);字符串用户名= properties.getProperty("my.username");System.out.println(用户名); 

尽管使用my.username属性和username变量,但Intellij IDEA表示未使用它.为什么 ?我试图使缓存无效并重新启动IDE,但是它没有任何改变.

因此,很难找出实际上未使用的属性并将其删除.

这是项目结构:

  PROJECT1->项目2->src>主要>资源>文件夹>my.properties->pom.xml->项目3->src>主要>Java>packagea.b.c>打包>包装Constants.java->pom.xmlpom.xml 

解决方案

该问题无法重现:

如果您有

请注意,应用程序模块取决于属性模块.通过以下的 pom.xml 配置,达到应用模块.

 < dependencies><依赖关系>< groupId> com.jetbrains.support</groupId>< artifactId>属性</artifactId>< version> 1.0-SNAPSHOT</version></dependency></dependencies> 

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

解决方案

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>

这篇关于为什么Intellij IDEA会说使用的属性未使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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