IntelliJ社区版Maven项目插件未找到 无法构建可执行Jar如何解决
问题解决方案
你遇到的插件找不到报错的核心原因是pom.xml中所有插件都未指定<version>标签,Maven无法定位到对应版本的插件包,才会出现未找到的错误。
第一步:修正pom.xml配置
给所有插件补充稳定可用的版本号即可,注意maven-shade-plugin和maven-assembly-plugin功能重叠,选一个使用即可,同时配置可能引发冲突。修正后的配置参考如下:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <executions> <execution> <goals> <goal>shade</goal> </goals> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>替换为你的实际主类全路径</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <finalName>ServiceCreate</finalName> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>com.svt.optimoo.App</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRef> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
第二步:补充版本后依然报错的排查方案
- 检查Maven镜像源:打开Mac系统下
~/.m2/settings.xml配置文件,确认配置了国内可用的镜像源,推荐阿里云镜像,配置片段如下:
<mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors>
- 强制更新Maven依赖:在IDEA的Maven面板点击执行命令按钮,输入
mvn clean compile -U执行,强制拉取缺失的插件包。 - 清理损坏的本地缓存:进入
~/.m2/repository/org/apache/maven/plugins路径,删除对应报错插件的文件夹,再重新加载Maven项目。
无需配置插件的替代打包方案
可以直接使用IDEA自带的功能生成可执行Jar,操作步骤如下:
- 打开
File > Project Structure > Artifacts - 点击
+号,选择JAR > From modules with dependencies - 选择你的项目模块和主类,勾选
copy to the output directory and link via manifest,点击确认 - 回到主界面点击
Build > Build Artifacts,选择刚创建的Jar配置点击Build即可,生成的可执行Jar会存放在项目out/artifacts目录下。
内容的提问来源于stack exchange,提问作者Sean
相关产品推荐
相关产品推荐

