稳哥真稳 2018-11-12 12:35 采纳率: 0%
浏览 1697

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条回答

  • dabocaiqq 2018-11-12 15:38
    关注
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?