Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile...

版权声明:转发请标明出处,谢谢! https://blog.csdn.net/Myuhua/article/details/84937206

报错信息: 这是在maven打包时候报的一个错误。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:
testCompile (default-testCompile) on project myproject_web: 
Compilation failure: Compilation failure: 
[ERROR] /D:/workspace/myproject/myproject_web/src/test/java/com/jd/FinalStaticTest.java:[4,22] 程序包com.jd.service不存在
[ERROR] /D:/workspace/myproject/myproject_web/src/test/java/com/jd/FinalStaticTest.java:[40,9] 找不到符号

报错原因:这边它报错信息说是包不存在,但是你通过import倒包处又可以点进去这个类中,其实不是包不存在,它是test下通过main的方式去调用其他包中的service导致相关信息找不到。

解决方法:设置一下测试资源目录就可以解决这个问题。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!--重新打包-->
            <executions>
                <execution>
                    <goals>
                        <goal>
                            repackage
                        </goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.jd.SpringBootStart</mainClass>
            </configuration>
        </plugin>
    </plugins>
    <!--测试代码目录(加入这一行)-->
    <testSourceDirectory>/src/test/java</testSourceDirectory>
</build>

猜你喜欢

转载自blog.csdn.net/Myuhua/article/details/84937206