IntelliJ执行Maven clean/build时项目及源码自动隐藏求助
Maven执行clean/build后项目源码自动隐藏的解决建议
问题现象
在IntelliJ IDEA中执行Maven的clean或build操作时,项目包含的源码会自动隐藏:
- 执行clean install前:

- 执行clean install后:

环境信息
IntelliJ IDEA版本
IntelliJ IDEA 2022.3.1 (Community Edition) Build #IC-223.8214.52, built on December 20, 2022 Runtime version: 17.0.5+1-b653.23 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.3.1 GC: G1 Young Generation, G1 Old Generation Memory: 8000M Cores: 10 Metal Rendering is ON Non-Bundled Plugins: com.intellij.properties.bundle.editor (223.7571.203) idea.plugin.protoeditor (223.8214.6) PMDPlugin (1.8.27) ink.organics.pojo2json (2.0.4) net.seesharpsoft.intellij.plugins.csv (3.0.2-223) camtwoTomcatRunner (1.7) com.poratu.idea.plugins.tomcat (4.3.8) com.bigmy (1.0) ChatGPT (2.1.10-222.231) com.ld.chatGPT-copilot (0.5.4) com.intellij.lang.jsgraphql (3.3.0) appland.appmap (0.42.1) SequenceDiagram (2.2.6) zielu.gittoolbox (213.10.5) org.sonarlint.idea (7.3.0.59206) aws.toolkit (1.67-223) Kotlin: 223-1.7.21-release-272-IJ8214.52
pom.xml内容
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.2.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.mapping</groupId> <artifactId>Mappingapi-Jwt</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Mappingapi-Jwt</name> <description>Demo project for Spring Boot</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> <version>0.12.3</version> </dependency> <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-impl</artifactId> <version>0.12.3</version> <scope>runtime</scope> </dependency> <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-jackson --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-jackson</artifactId> <version>0.12.3</version> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
解决建议
- 检查项目视图过滤规则:点击Project视图右上角的齿轮图标,确认
Hide Empty Middle Packages等选项未异常勾选,且无手动添加的过滤规则隐藏源码目录。 - 重新导入Maven项目:点击右侧Maven面板的刷新按钮,选择
Reload All Maven Projects,让IDEA重新识别项目结构。 - 排查插件冲突:当前安装的第三方插件较多,建议临时禁用所有非必要插件(如ChatGPT相关、Tomcat运行插件),重启IDEA后再执行Maven操作,确认是否为插件导致的问题。
- 查看Maven执行日志:执行
mvn clean -X查看详细日志,排查是否有异常操作影响了源码目录的显示。 - 清理IDEA缓存:通过
File -> Invalidate Caches... -> Invalidate and Restart清理缓存并重启,解决缓存导致的结构识别异常。 - 确认源码目录标记:右键源码目录(如
src/main/java),选择Mark Directory as -> Sources Root,确保IDEA正确识别源码根目录,避免Maven操作后丢失标记。
内容的提问来源于stack exchange,提问作者Shiva
相关产品推荐
相关产品推荐

