当我开始学习spring boot时,我做了一个项目springboot-demo作为root,一个三个模块的admin-service,common-service和dao。
这是root pom:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<name>springboot-demo</name>
<modules>
<module>admin-service</module>
<module>common-service</module>
<module>dao</module>
</modules>
<groupId>cc.xiaoerbi</groupId>
<artifactId>springboot-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<mybatis-spring-boot>1.2.0</mybatis-spring-boot>
<mysql-connector>5.1.39</mysql-connector>
</properties>
</project>
这是管理员:
<?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/maven-v4_0_0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>cc.xiaoerbi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<name>admin-service</name>
<artifactId>admin-service</artifactId>
<dependencies>
<dependency>
<groupId>cc.xiaoerbi</groupId>
<artifactId>dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Spring Boot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这就是dao pom:
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>cc.xiaoerbi</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>dao</artifactId>
<dependencies>
<!-- Spring Boot Mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
我打包管理员战争失败了 告诉:
[警告] cc.xiaoerbi的pOM:dao:jar:缺少1.0-SNAPSHOT,没有可用的依赖信息
我已经编写了一些类似的代码,但它确实有效。我不知道这段代码有什么问题。
答案 0 :(得分:0)
更改您的模块,以便在使用之前编译您的dependecies。
<modules>
<module>dao</module>
<module>admin-service</module>
<module>common-service</module>
</modules>
包含dao,admin-service和common-service pom.xml的文件夹名称应位于根文件夹中,它们应与根pom.xml中的模块名称匹配。此外,您应该从根目录而不是管理目录运行“mvn clean install”编译。如果从admin编译,它将不会首先编译dao。当它无法在〜/ .m2 / repositoy本地缓存中找到资源时,它会尝试从repo中提取。
添加
<relativePath>../pom.xml</relativePath>
到admin-service和common-service。
他们在https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
上的项目继承部分示例2中讨论它