我想创建一个maven依赖Spring boot并在其他项目中使用它。但我编译错误...
[INFO] [1m--- [0;32mcompiler:3.13.0:compile[m [1m(default-compile)[m @ [36msso[0;1m ---[m
[INFO] Recompiling the module because of [1mchanged source code[m.
[INFO] Compiling 3 source files with javac [debug parameters release 21] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/workspaces/test/sso/src/main/java/ir/com/sso/domain/entity/User.java:[3,35] package ir.com.common.domain.entity does not exist
[ERROR] /D:/workspaces/test/sso/src/main/java/ir/com/sso/domain/entity/User.java:[20,27] cannot find symbol
symbol: class BaseEntity
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] [1m------------------------------------------------------------------------[m
[INFO] [1;31mBUILD FAILURE[m
[INFO] [1m------------------------------------------------------------------------[m
[INFO] Total time: 5.267 s
[INFO] Finished at: 2024-12-06T10:06:06+03:30
[INFO] [1m------------------------------------------------------------------------[m
[ERROR] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile[m [1m(default-compile)[m on project [36msso[m: [1;31mCompilation failure[m: Compilation failure:
[ERROR] /D:/workspaces/test/sso/src/main/java/ir/com/sso/domain/entity/User.java:[3,35] package ir.com.common.domain.entity does not exist
[ERROR] /D:/workspaces/test/sso/src/main/java/ir/com/sso/domain/entity/User.java:[20,27] cannot find symbol
[ERROR] symbol: class BaseEntity
[ERROR] -> [1m[Help 1][m
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the [1m-e[m switch.
[ERROR] Re-run Maven using the [1m-X[m switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [1m[Help 1][m http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我的
pom.xml
在common
项目中是:
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>ir.com</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>common</name>
<packaging>pom</packaging>
<description>common project for extend</description>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>...<dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
而我在
pom.xml
项目中的 sso
是:
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>ir.com</groupId>
<artifactId>sso</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sso</name>
<description>Demo project for SSO</description>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>ir.com</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
...
我的
common
项目构建成功。但是sso
项目有错误。
我在我的
plugin
parent
中添加了这个pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
构建后,所有事情都是正确的