J'ajoute un nouveau module maven au projet. Il utilisera Spring-Boot. Les anciens modules ne l'utilisent pas. Donc, mon nouveau module doit être enfant du projet parent mais en même temps, il doit être un enfant de printemps-boot-starter-parent. Comment puis-je faire mon projet enfant de 2 parents différents?
Mon parent actuel
<parent>
<groupId>com.somegroup</groupId>
<artifactId>Parent</artifactId>
<version>1.0</version>
</parent>
Parent de démarrage
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
Réponses:
2 pour la réponse № 1Comme le projet Maven ne peut avoir qu'un seul parent, vous pouvez utiliser une approche différente. Au lieu de l'héritage, vous pouvez importer spring-boot-dependencies
dans la section de gestion des dépendances et conservez le parent d'origine.
<parent>
<groupId>com.somegroup</groupId>
<artifactId>Parent</artifactId>
<version>1.0</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Vous pouvez lire sur les contraintes dans la documentation officielle, qui concernent essentiellement la façon dont vous modifiez la version des dépendances fournie par Spring Boot.
0 pour la réponse № 2
Vous devrez définir un autre parent situé entre spring-boot et vos propres modules, et voici un exemple:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<groupId>com.greg</groupId>
<artifactId>myparent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>