maven多模块项目打包失败

1.项目结构

            parent-demo
                    - service-demo
                    - web-demo

            2.其中web-demo依赖service-demo

            3.三个项目之间的pom.xml分别如下

            parent-demo


            ```
            <?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">

                    <!--基本信息-->
                    <description>maven 多模块项目构建</description>
                    <modelVersion>4.0.0</modelVersion>
                    <name>parent-demo</name>
                    <packaging>pom</packaging>

                    <!--项目说明-->
                    <groupId>com.lanyage.multimodule</groupId>
                    <artifactId>parent-demo</artifactId>
                    <version>1.0-SNAPSHOT</version>

                    <!--继承说明-->
                    <parent>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-parent</artifactId>
                            <version>2.0.6.RELEASE</version>
                            <relativePath/>
                    </parent>

                    <!--声明子模块-->
                    <modules>
                            <module>service-demo</module>
                            <module>web-demo</module>
                    </modules>

                    <!--版本说明,在这里声明的依赖在子模块中也需要<dependencies/>引入,但是子模块中就不需要版本了。-->
                    <dependencyManagement>
                            <dependencies>
                                    <dependency>
                                            <groupId>com.lanyage.multimodule</groupId>
                                            <artifactId>service-demo</artifactId>
                                            <version>0.0.1-SNAPSHOT</version>
                                    </dependency>
                                    <dependency>
                                            <groupId>com.lanyage.multimodule</groupId>
                                            <artifactId>web-demo</artifactId>
                                            <version>0.0.1-SNAPSHOT</version>
                                    </dependency>
                            </dependencies>
                    </dependencyManagement>
            </project>
            ```
            service-demo



            ```
            <?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">


                    <!--基本信息-->
                    <modelVersion>4.0.0</modelVersion>
                    <packaging>jar</packaging>
                    <name>service-demo</name>
                    <description>Demo project for Spring Boot</description>

                    <groupId>com.lanyage.multimodule</groupId>
                    <artifactId>service-demo</artifactId>
                    <version>0.0.1-SNAPSHOT</version>

                    <properties>
                            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                            <java.version>1.8</java.version>
                    </properties>

                    <!--继承父工程-->
                    <parent>
                            <groupId>com.lanyage.multimodule</groupId>
                            <artifactId>parent-demo</artifactId>
                            <version>1.0-SNAPSHOT</version>
                    </parent>

                    <!--依赖-->
                    <dependencies>
                            <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter</artifactId>
                            </dependency>

                            <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-test</artifactId>
                                    <scope>test</scope>
                            </dependency>
                    </dependencies>

                    <build>
                            <plugins>
                                    <plugin>
                                            <groupId>org.springframework.boot</groupId>
                                            <artifactId>spring-boot-maven-plugin</artifactId>
                                    </plugin>
                            </plugins>
                    </build>
            </project>

            ```
            web-demo


            ```
            <?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">
                    <modelVersion>4.0.0</modelVersion>

                    <groupId>com.lanyage.multimodule</groupId>
                    <artifactId>web-demo</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <packaging>jar</packaging>

                    <name>web-demo</name>
                    <description>Demo project for Spring Boot</description>

                    <parent>
                            <groupId>com.lanyage.multimodule</groupId>
                            <artifactId>parent-demo</artifactId>
                            <version>1.0-SNAPSHOT</version>
                    </parent>

                    <properties>
                            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                            <java.version>1.8</java.version>
                    </properties>

                    <dependencies>
                            <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-web</artifactId>
                            </dependency>

                            <dependency>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-test</artifactId>
                                    <scope>test</scope>
                            </dependency>

                            <dependency>
                                    <groupId>com.lanyage.multimodule</groupId>
                                    <artifactId>service-demo</artifactId>
                                    <version>0.0.1-SNAPSHOT</version>
                            </dependency>
                    </dependencies>

                    <build>
                            <plugins>
                                    <plugin>
                                            <groupId>org.springframework.boot</groupId>
                                            <artifactId>spring-boot-maven-plugin</artifactId>
                                    </plugin>
                            </plugins>
                    </build>


            </project>

            ```

        4.打包web-demo时,报错如下。

        ```
        [ERROR] Failed to execute goal on project web-demo: Could not resolve dependencies for project com.lanyage.multimodule:web-demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.lanyage.multimodule:service-demo:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.lanyage.multimodule:service-demo:jar:0.0.1-SNAPSHOT: Could not find artifact com.lanyage.multimodule:parent-demo:pom:1.0-SNAPSHOT -> [Help 1]
        [ERROR] 
        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
        [ERROR] 
        [ERROR] For more information about the errors and possible solutions, please read the following articles:
        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
        ```

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问