我正在尝试使用父项目和子项目来重构一个非常复杂的maven项目。它使用一些Spring Boot和Spring依赖项。在父pom中,<dependencies>
下只定义了几个依赖项(在所有子项目中继承的全局依赖项)。其余部分在<dependencyManagement>
下定义,以便为整个项目定义一个版本。每个子项目都定义了自己的<dependencies>
,而没有设置版本。
但版本管理很混乱;在父pom中,每个依赖项版本都使用全局属性定义。
我想使用平台bom:我尝试过一个父平台-bom。
适用于<dependencies>
但不适用于<dependencyManagement>
。
在子项目中,未定义版本;有解决方案吗?
'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-tomcat:jar is missing
修改
父母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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp-parent</artifactId>
<version>1.0.0</version>
<name>Parent Project</name>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.io.version>2.0.3.RELEASE</spring.io.version>
<spring.boot.version>1.3.3.RELEASE</spring.boot.version>
</properties>
<parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>2.0.3.RELEASE</version>
<!--<relativePath />-->
</parent>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<!--<version>${spring.boot.version}</version>-->
</dependency>
<!-- devtools (ressources hot swap) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<!--<version>${spring.boot.version}</version>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!--<version>${spring.boot.version}</version>-->
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<!-- JPA support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<!-- H2 database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.191</version>
</dependency>
<!-- Project sub modules -->
<dependency>
<groupId>com.myapp</groupId>
<artifactId>myapp-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.myapp</groupId>
<artifactId>myapp-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Other -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.1</version>
</dependency>
<!-- And some more dependencies... -->
</dependencyManagement>
<modules>
<module>myapp-common</module>
<module>myapp-core</module>
</modules>
</project>
其中一个子项目
<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>
<artifactId>myapp-core</artifactId>
<description>Core</description>
<parent>
<groupId>com.myapp</groupId>
<artifactId>myapp-parent</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<!-- JPA support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- H2 database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>