maven继承父工程的本地jar爆红

211 阅读1分钟

tag: 明明jar下载到本地了还是爆红

问题如下:

父工程的配置

<?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> <http://maven.apache.org/xsd/maven-4.0.0.xsd>">
    <parent>
        <artifactId>heima-leadnews</artifactId>
        <groupId>com.heima</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>heima-leadnews-service</artifactId>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <modules>
        <module>heima-leadnews-user</module>
    </modules>

    <dependencies>
        <!-- 引入依赖模块 -->
        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>heima-leadnews-model</artifactId>
        </dependency>
        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>heima-leadnews-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>heima-leadnews-feign-api</artifactId>
        </dependency>
        ...
    </dependencies>

</project>

除了上面的我们微服务的jar包外还有很多网络拉取的。

子工程的配置

<?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>com.heima</groupId>
		<artifactId>heima-leadnews-service</artifactId>
		<version>1.0-SNAPSHOT</version>
		<relativePath>../../heima-leadnews-service</relativePath>
	</parent>
	<groupId>com.heimaleadnewsuser</groupId>
	<artifactId>heima-leadnews-user</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>heima-leadnews-user</name>
	<description>heima-leadnews-user</description>
	<properties>
		<maven.compiler.source>8</maven.compiler.source>
		<maven.compiler.target>8</maven.compiler.target>
	</properties>
</project>

刷新时报错信息如下:

在右边栏的maven中查看依赖就是这三个本地jar爆红

但是,这三个jar明明下载到本地了啊,为什么还会爆红呢?不应该啊

解决办法如下:

修改子工程的配置为如下:

<?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>com.heima</groupId>
		<artifactId>heima-leadnews-service</artifactId>
		<version>1.0-SNAPSHOT</version>
		<relativePath>../../heima-leadnews-service</relativePath>
	</parent>
	<artifactId>heima-leadnews-user</artifactId>
	<name>heima-leadnews-user</name>
	<description>heima-leadnews-user</description>
	<properties>
		<maven.compiler.source>8</maven.compiler.source>
		<maven.compiler.target>8</maven.compiler.target>
	</properties>
</project>

问题解决,很离谱!