5
votes

Comment construire un projet Maven multi-module sans classe principale dans l'un des modules

J'ai essayé de trouver une réponse à ce problème dans des questions similaires, mais je ne sais toujours pas ce qui le cause.

J'ai un projet maven multi-module et j'essaye d'exécuter mvn install ou package mvn et j'obtiens l'erreur suivante

Application [INFO] ........................................... ........ SUCCÈS [1,025 s]

[INFO] module-data ..................................... FAILURE [ 0,952 s]

[INFO] module-app ...................................... SKIPPED p>

[ERROR] Échec de l'exécution de l'objectif org.springframework.boot: spring-boot-maven-plugin: 2.1.1.RELEASE: reconditionnement (reconditionnement) sur projet project-data: Exécution reconditionnement de l'objectif org.springframework.boot: spring-boot-maven-plugin: 2.1.1.RELEASE: reconditionnement échec: impossible de trouver la classe principale -> [Aide 1]

Le module project-app a une classe java dans le dossier src, alors que le module project-data n'a pas de classe principale. p>

pom.xml parent

<?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">
    <parent>
        <artifactId>app</artifactId>
        <groupId>com.example</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>project-app</artifactId>

    <dependencies>
        <dependency>
            <artifactId>project-data</artifactId>
            <groupId>com.example</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


</project>

data-projet pom.xml

<?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">
    <parent>
        <artifactId>app</artifactId>
        <groupId>com.example</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>project-data</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

projet-app pom. xml

<?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>
    <packaging>pom</packaging>
    <modules>
        <module>project-data</module>
        <module>project-app</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>app</name>
    <description></description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

J'ai quelque chose de très similaire à la structure de ce projet (sfg-pet-clinic), cependant, après avoir téléchargé et exécuté package mvn , cela fonctionne très bien. Je ne vois pas beaucoup de différence entre les fichiers pom de mon projet et celui-ci alors que pourrais-je manquer?


3 commentaires

si la classe principale est dans un autre module que le plugin de démarrage, vous pouvez spécifier cette classe principale dans la configuration du plugin: docs.spring.io/spring-boot/docs/current/maven-plugin/...


de rien :)


Lien mis à jour: docs.spring.io/spring- boot / docs / current / maven-plugin / referen‌ ce /…


5 Réponses :


4
votes

Je déplacerais toute la section

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

du parent vers le module module-app, car celui-ci est le module unique qui utilise la fonctionnalité de reconditionnement.

De plus, je supprimerais également la section plugin du module-data, car il n'est pas nécessaire de reconditionner ce module.


0 commentaires

2
votes

Merci à @wemu pour la section commentaires.

L'ajout de ceci:

<configuration>
    <mainClass> ${your.start.Class}</mainClass>
</configuration>

à la section plugin est requis sur la version 2.1.1.RELEASE du spring-boot-starter-parent dépendance, tant que votre classe est dans un autre module.

Le projet sfg-pet-clinic auquel j'ai fait référence dans ma question utilise une version plus ancienne qui n'a pas besoin du Configuration de


2 commentaires

Je ne sais pas qui a voté contre cela. merci d'avoir documenté votre réponse à la question. Si cela répond à votre question, acceptez-le aussi :)


Je ne sais pas pourquoi la bonne réponse est rejetée, mais merci encore @wemu;) Je viens de l'accepter



0
votes

D'accord, voici comment j'ai résolu ce problème.

Mes étapes étaient:

  1. Changer l'empaquetage du fichier pom.xml pour les données de projet en pom à partir de jar (j'ai utilisé la vue d'ensemble d'Eclipse)
  2. ajoutez pom dans le fichier pom.xml pour project-app pour la dépendance du module-data
        <dependency>
            <groupId>samee.springframework</groupId>
            <artifactId>project-data</artifactId>
            <version>0.0.1-SNAPSHOT</version>
             <type>pom</type>
        </dependency>  

Ensuite, vous pouvez exécuter votre nettoyage et package / installation


0 commentaires

0
votes

Je viens de changer la version de Spring Boot dans le pom.xml parent de 2.1.1 à 2.0.3 et cela fonctionne.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

Il vaudrait mieux le faire fonctionner en 2.1.1 cependant, mais c'est une solution simple et rapide.


0 commentaires

5
votes

La configuration concerne les anciennes versions de Spring.

Supprimer:

 <parent>
        <artifactId>mc-pet-clinic</artifactId>
        <groupId>guru.springframework</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>pet-clinic-data</artifactId>

    <properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
    </properties>

...

À la place, ajoutez cet indicateur ci-dessous pom artifactId

   <properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
    </properties>

Comme ceci:

    <configuration>
       <skip>true</skip>
    </configuration>

p >


0 commentaires