NutzCN Logo
问答 基于springboot2.0的maven项目, install时报错找不到包
发布于 2163天前 作者 qq_99c1b36f 9440 次浏览 复制 上一个帖子 下一个帖子
标签:

我搭建了一个spring-boot2.0的maven项目,多个模块。项目能运行,但是在mvn install时报错:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /G:/workspace1/pmp/admin/src/main/java/com/sdcm/admin/dao/TestDao.java:[3,34] 程序包com.sdcm.common.utils.date不存在
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.946 s
[INFO] Finished at: 2018-05-24T10:29:59+08:00
[INFO] Final Memory: 38M/285M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project admin: Compilation failure
[ERROR] /G:/workspace1/pmp/admin/src/main/java/com/sdcm/admin/dao/TestDao.java:[3,34] 程序包com.sdcm.common.utils.date不存在
[ERROR] -> [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/MojoFailureException

---------------------------------------------------------------------------------------------------------------------------------------------------------------

自己百度,也到各种群里问过,但是还是不能解决,特来求教wendal大神,虽然不是nutz相关,但是大神是善良的对吗?

下面附上说明:
1.项目叫pmp,里面有一个主pom,pmp下有两个子模块,admin和common,admin依赖common,当admin中不import common中
的类时,admin 的mvn install正常,import后就报错如上。但是admin能用main方法正常启动且无报错。
-----初步怀疑是admin的pom里面的build不对,下面贴上
2. admin的pom.xml

<?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.sdcm</groupId>
    <artifactId>admin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>admin</name>
    <description>pmp权限控制模块</description>

    <!-- 声明父模块,继承父模块的依赖 -->
    <parent>
        <groupId>com.sdcm</groupId>
        <artifactId>pmp</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>com.sdcm</groupId>
            <artifactId>common</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>

  1. common的pom.xml
<?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.sdcm</groupId>
    <artifactId>common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>common</name>
    <description>pmp公共模块</description>

    <!-- 声明父模块,继承父模块的依赖 -->
    <parent>
        <groupId>com.sdcm</groupId>
        <artifactId>pmp</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>
    </dependencies>

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


</project>

@wendal

36 回复

项目使用idea内置的spring initializr创建的

parent项目里面,声明这两个module没

声明了,以下是总pom.xml

<!-- 1.父模块声明 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/>
    </parent>

    <!-- 2.子模块声明 -->
    <modules>
        <module>common</module>
        <module>admin</module>
        <module>workflow</module>
        <module>service-yuzheng</module>
        <module>web</module>
    </modules>

如果admin或者web中,不import common的代码,就能通过mvn install,import了就不能,
另外,
mvn dependency:tree 能通过

install一下,在顶层目录

试过了 import了类的模块全部失败,

会不是是我的maven setting.xml配置的不对,或者是我项目中pom的写的不对

不应该import,只应该dependency

admin pom里面是dependency了common,这时候mvn install不报错,但是admin模块里面的类,import了common中的类后,mvn install就会报错说这个类不存在,即使先将common :mvn install后,再admin:mvn install也会报错

哦,你指的import是java代码里面的import

在根目录install呢?

在根目录install也一样,import了别的模块代码的模块会报错,没有import的代码的不会

大神有空吗,要不我上传到github,您给看看???

嗯,传呗,码云也可以

在线等回复 = =

commom项目的pom.xml,删掉这个plugin就可以的, 作为依赖项的module, 不能加这个plugin的

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

我试过,还是不行。你那边这样就可以吗?

可以的啊,贴你的日志看看

CommonApplication.java 也删掉

我把common pom里面的注释掉了并更新,单独对common install正常,但是单独对admin installl就还是报那个错,然后我把CommonApplication.java删掉了后,common就没法install了,因为它没法跑test

里面的plugin标签内容

在根目录下执行,然后贴输出

mvn clean package -Dmaven.test.skip=true
G:\workspace1\pmp>mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] pmp
[INFO] common
[INFO] admin
[INFO] workflow
[INFO] service-yuzheng
[INFO] web
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pmp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ pmp ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building common 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ common ---
[INFO] Deleting G:\workspace1\pmp\common\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to G:\workspace1\pmp\common\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ common ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ common ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ common ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ common ---
[INFO] Building jar: G:\workspace1\pmp\common\target\common-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building admin 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ admin ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ admin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ admin ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to G:\workspace1\pmp\admin\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ admin ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ admin ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ admin ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ admin ---
[INFO] Building jar: G:\workspace1\pmp\admin\target\admin-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ admin ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building workflow 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ workflow ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ workflow ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ workflow ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to G:\workspace1\pmp\workflow\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ workflow ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ workflow ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ workflow ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ workflow ---
[INFO] Building jar: G:\workspace1\pmp\workflow\target\workflow-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ workflow ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building service-yuzheng 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ service-yuzheng ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ service-yuzheng ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ service-yuzheng ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to G:\workspace1\pmp\service-yuzheng\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ service-yuzheng ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ service-yuzheng ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ service-yuzheng ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ service-yuzheng ---
[INFO] Building jar: G:\workspace1\pmp\service-yuzheng\target\service-yuzheng-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ service-yuzheng ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building web 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ web ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 34 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to G:\workspace1\pmp\web\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /G:/workspace1/pmp/web/src/main/java/com/sdcm/web/controller/admin/UserCtl.java:[3,26] 程序包com.sdcm.admin.dao不存在
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] pmp ................................................ SUCCESS [  0.185 s]
[INFO] common ............................................. SUCCESS [  2.399 s]
[INFO] admin .............................................. SUCCESS [  4.575 s]
[INFO] workflow ........................................... SUCCESS [  0.410 s]
[INFO] service-yuzheng .................................... SUCCESS [  0.408 s]
[INFO] web ................................................ FAILURE [  0.509 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.071 s
[INFO] Finished at: 2018-05-24T14:21:14+08:00
[INFO] Final Memory: 47M/312M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project web: Compilation failure
[ERROR] /G:/workspace1/pmp/web/src/main/java/com/sdcm/web/controller/admin/UserCtl.java:[3,26] 程序包com.sdcm.admin.dao不存在
[ERROR] -> [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/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :web

G:\workspace1\pmp>

是不是所有的凡是被别人dependency的模块,都要去掉自己的 build plugin

嗯, 没毛病, web要引用admin的话, admin也不能加plugin的

目测你的admin也是独立运行的, web不应该依赖它吧

admin里面提供service,web里面要注入admin service,web模块专门做控制层

如果按照你这样的话,所有的被dependency的模块都不能自己build plugin,那就意味着无法单独install对吗

为啥不能install? 因为test不过???

如果test不过,那是testcase不对或者不合理, 跟maven没毛线关系

明白了,只是maven默认帮我跑了test

我不知道我搭建的框架结构是否合理,能给点意见吗。

说明:
- admin : 权限和系统模块(提供dao,service,mapper)
- common : 公共模块(提供实体类,工具类,视图类,常亮,自定义异常)
- workflow :工作流模块(提供dao,service,mapper)
- service-x:业务模块X(提供dao,service,mapper)

  • web: 提供控制器的功能(controller ,静态资源,filter等)
  • 如果需要拓展新的业务模块,就新建一个module:service-newName

    问题:
  • 1.这样的构想是否合理
  • 2.每个模块的配置文件,是否有冗余部分

持久层计划用mybatis + mysql + (别的再拓展)

没有意见,不给意见

添加回复
请先登陆
回到顶部