Maven项目引用本地jar包依赖打包警告Some problems were encountered while building the effective model for com.xxx:xxx:jar should not point at files within the project directory
导入本地包WARNING警告的配置如下:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cad</artifactId>
<version>19.9</version>
<scope>system</scope>
<!-- WARNING警告点 -->
<systemPath>${project.basedir}/lib/aspose-cad-19.9.jar</systemPath>
</dependency>
<dependency>
<groupId>cpdetector</groupId>
<artifactId>cpdetector</artifactId>
<version>1.04</version>
<scope>system</scope>
<!-- WARNING警告点 -->
<systemPath>${project.basedir}/lib/cpdetector-1.04.jar</systemPath>
</dependency>
警告信息:
Some problems were encountered while building the effective model for com.xxx.xxx:xxx-xxx:jar:3.3.0
'dependencies.dependency.systemPath' for com.aspose:aspose-cad:jar should not point at files within the project directory, ${project.basedir}/lib/aspose-cad-19.9.jar will be unresolvable by dependent projects @ line 177, column 25
'dependencies.dependency.systemPath' for cpdetector:cpdetector:jar should not point at files within the project directory, ${project.basedir}/lib/cpdetector-1.04.jar will be unresolvable by dependent projects @ line 185, column 25
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.
大概意思是:
在打包时
com.xxx.xxx:xxx-xxx:jar:3.3.0遇到了一些问题,dependencies.dependency.systemPath下的com.aspose:aspose-cad:jar不应该指向项目目录。
在177行25列${project.basedir}/lib/aspose-cad-19.9.jar将无法解析依赖。
在185行25列${project.basedir}/lib/cpdetector-1.04.jar将无法解析依赖。
强烈建议修复这些问题,因为它们威胁到构建的稳定性。
因为在未来的Maven版本可能不再支持构建这种格式错误的项目。
报了这个警告但是包都能正常打进去,网上有人说打不进去,按照网上的方式包反而打不进去了。
搜到的解决方式参见:blog.csdn.net/asing1elife…
解决方案:
方案一:使用插件引入本地jar包:
- 去掉
<scope>、<systemPath>标签,即改为:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cad</artifactId>
<version>19.9</version>
</dependency>
<dependency>
<groupId>com.cpdetector</groupId>
<artifactId>cpdetector</artifactId>
<version>1.04</version>
</dependency>
- 然后使用插件导入本地jar包,这里有提供2种方式:
- 使用
spring-boot-maven-plugin插件:关键配置<argument>${project.basedir}\lib</argument>导入lib下的所有jar包
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments>
<argument>${project.basedir}\lib</argument>
</arguments>
</configuration>
</plugin>
- 或使用
maven-compiler-plugin插件:关键配置<extdirs>${project.basedir}\lib</extdirs>导入lib下的所有jar包。
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<optimize>true</optimize>
<!-- 导入\lib下的本地jar包 -->
<compilerArguments>
<extdirs>${project.basedir}\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
优点:
- 解除了以上打包警告。
- 可以单个导入jar包,如果本地jar依赖比较多,也可以直接导入
\lib目录下的所有jar包。缺点:
- 引入了新的插件。
- ······
方案二:将jar包添加到本地(私有)仓库中:
# 以aspose-cad-19.9.jar为例,进入到jar包所在目录,执行以下Maven命令
mvn install:install-file -DgroupId=com.aspose -DartifactId=aspose-cad -Dversion=19.9 -Dpackaging=jar -Dfile=aspose-cad-19.9.jar
优点:
- 解除了以上打包警告。
- 使用上和普通jar包没有区别。
缺点:
- 需要将jar包添加到Maven私服仓库,没有私服的需要通知每个开发者将jar包添加到本地仓库。