IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Maven Java Discussion :

Build fail - Tests avec super classe dans un autre projet


Sujet :

Maven Java

  1. #1
    Expert éminent
    Avatar de Matthieu Vergne
    Homme Profil pro
    Consultant IT, chercheur IA indépendant
    Inscrit en
    Novembre 2011
    Messages
    2 270
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant IT, chercheur IA indépendant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2 270
    Points : 7 792
    Points
    7 792
    Billets dans le blog
    3
    Par défaut Build fail - Tests avec super classe dans un autre projet
    Bonjour,

    Je suis en train de me former (sur le tas) a maven, et il se trouve que j'ai un projet ayant cette structure :

    - project 1
    -- class Model
    -- class TestModel

    - project 2 depend de project 1
    -- class Example extends Model
    -- class TestExample extends TestModel

    Comme vous pouvez le voir, je definis un modele et son test dans un projet, puis j'ai un autre projet qui definit une implementation particuliere de ce modele et les tests qui lui sont associes. Pour etre sur de le tester a fond, le test etend celui du modele (c'est fait pour evidemment, j'ai des fonctions a implementer pour pouvoir appliquer les tests du modele sur des instances des exemples). Sous Eclipse ca marche tres bien (run+test). Par contre sous Maven je n'arrive pas a avoir une compilation complete du projet 2.

    Voila les poms adaptes (juste les noms de changes) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <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>...</groupId>
    		<artifactId>parent</artifactId>
    		<version>...</version>
    	</parent>
     
    	<artifactId>project1</artifactId>
    	<name>...</name>
    	<description>...</description>
    	<inceptionYear>...</inceptionYear>
     
    	<developers>
    		<developer>
    			<name>...</name>
    			<email>...</email>
    		</developer>
    	</developers>
     
    	<dependencies>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.8.2</version>
    			<scope>test</scope>
    		</dependency>
    	</dependencies>
    </project>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    <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>...</groupId>
    		<artifactId>parent</artifactId>
    		<version>...</version>
    	</parent>
     
    	<artifactId>project2</artifactId>
    	<name>...</name>
    	<description>...</description>
    	<inceptionYear>...</inceptionYear>
     
    	<developers>
    		<developer>
    			<name>...</name>
    			<email>...</email>
    		</developer>
    	</developers>
     
    	<dependencies>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.8.2</version>
    			<scope>test</scope>
    		</dependency>
    		<dependency>
    			<groupId>${project.parent.groupId}</groupId>
    			<artifactId>project1</artifactId>
    			<version>LATEST</version>
    			<scope>compile</scope>
    		</dependency>
    	</dependencies>
    </project>
    Et quand sous Eclipse je lui demande de compiler, lancer les tests et tout par les fonctionnalites de base (sans passer par Maven), tout est bon. Ca compile, ca teste, ca lance. En revanche, quand, toujours sous Eclipse, je lui demande de me faire un Maven install, le projet 1 tout va bien, mais le projet 2 voila ce que ca me fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Project 2 1.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ project2 ---
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory /media/HDD/Java/project2/src/main/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ project2 ---
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [INFO] Compiling 2 source files to /media/HDD/Java/project2/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ project2 ---
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory /media/HDD/Java/project2/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ project2 ---
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [INFO] Compiling 1 source file to /media/HDD/Java/project2/target/test-classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[21,27] cannot find symbol
    symbol  : class TestModel
    location: package project
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[32,2] cannot find symbol
    symbol: class TestModel
    		TestModel<Prioritization, Collection<Prioritization>> {
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[34,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[42,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[56,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[84,35] cannot find symbol
    symbol  : method createRequirements(int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[141,35] cannot find symbol
    symbol  : method createRequirements(int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[211,35] cannot find symbol
    symbol  : method createRequirements(int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[495,28] cannot find symbol
    symbol  : method createStudyCase1()
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[676,28] cannot find symbol
    symbol  : method createStudyCase1()
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[705,2] cannot find symbol
    symbol  : method fillManagerWithRandomData(project.DataManager,int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[746,2] cannot find symbol
    symbol  : method fillManagerWithRandomData(project.DataManager,int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[786,35] cannot find symbol
    symbol  : method createRequirements(int)
    location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[789,4] cannot find symbol
    symbol  : method createRandomPrioritization(java.util.List<project.Requirement>)
    location: class project.TestExample
    [INFO] 14 errors 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.742s
    [INFO] Finished at: Fri Nov 18 17:41:18 CET 2011
    [INFO] Final Memory: 11M/86M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project project2: Compilation failure: Compilation failure:
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[21,27] cannot find symbol
    [ERROR] symbol  : class TestModel
    [ERROR] location: package project
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[32,2] cannot find symbol
    [ERROR] symbol: class TestModel
    [ERROR] TestModel<Prioritization, Collection<Prioritization>> {
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[34,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[42,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[56,1] method does not override or implement a method from a supertype
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[84,35] cannot find symbol
    [ERROR] symbol  : method createRequirements(int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[141,35] cannot find symbol
    [ERROR] symbol  : method createRequirements(int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[211,35] cannot find symbol
    [ERROR] symbol  : method createRequirements(int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[495,28] cannot find symbol
    [ERROR] symbol  : method createStudyCase1()
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[676,28] cannot find symbol
    [ERROR] symbol  : method createStudyCase1()
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[705,2] cannot find symbol
    [ERROR] symbol  : method fillManagerWithRandomData(project.DataManager,int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[746,2] cannot find symbol
    [ERROR] symbol  : method fillManagerWithRandomData(project.DataManager,int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[786,35] cannot find symbol
    [ERROR] symbol  : method createRequirements(int)
    [ERROR] location: class project.TestExample
    [ERROR] /media/HDD/Java/project2/src/test/java/project/TestExample.java:[789,4] cannot find symbol
    [ERROR] symbol  : method createRandomPrioritization(java.util.List<project.Requirement>)
    [ERROR] location: class project.TestExample
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    Notez que je n'ai pas d'erreur pour les classes non test (Model + Example ici), seules les classes de test m'embetent ici.

  2. #2
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Points : 7 275
    Points
    7 275
    Par défaut
    Bonjour,

    Pour Maven, un projet Java va se diviser en 2 : d'une part le JAR qui contient le code source de l'application, d'autre part, le JAR contenant le code source des tests.

    Pour résoudre ton problème, il faut faire 2 choses :

    1. Demander à Maven de créer et déployer / installer le JAR de test de ton premier module. Cela se fait simplement dans le pom.xml comme ceci :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

    Grâce à cela, Maven déploiera non seulement ta lib.jar, mais aussi lib-tests.jar.

    2. Il faut déclarer dans ton second module, une dépendance au premier module (comme tu l'as fait), mais cette fois ci sur le JAR de test :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            <dependency>
                <groupId>${project.parent.groupId}</groupId>
                <artifactId>project1</artifactId>
                <version>LATEST</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>

    Là, ça devrait aller mieux !

  3. #3
    Expert éminent
    Avatar de Matthieu Vergne
    Homme Profil pro
    Consultant IT, chercheur IA indépendant
    Inscrit en
    Novembre 2011
    Messages
    2 270
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant IT, chercheur IA indépendant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2 270
    Points : 7 792
    Points
    7 792
    Billets dans le blog
    3
    Par défaut
    Je rajoute la dépendance ou je la remplace ?

    J'avais déjà rajouté ce style de dépendance (copier-coller de l'autre + changer le scope à test), et ça m'avait surchargé la première dépendance, du coup j'avais plus celle à la compilation des sources. Cela dit je n'avais pas de type spécifique.

  4. #4
    Expert éminent
    Avatar de Matthieu Vergne
    Homme Profil pro
    Consultant IT, chercheur IA indépendant
    Inscrit en
    Novembre 2011
    Messages
    2 270
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant IT, chercheur IA indépendant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2 270
    Points : 7 792
    Points
    7 792
    Billets dans le blog
    3
    Par défaut
    Alors j'ai ajouté la génération + la dépendance. Effectivement il me génère le JAR de test et il ne me fait plus d'erreur de compilation... il me dit carrément qu'il est incapable de trouver la dépendance :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Project 2 1.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.472s
    [INFO] Finished at: Mon Nov 21 16:11:49 CET 2011
    [INFO] Final Memory: 3M/89M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project project2: Could not resolve dependencies for project groupId:project2:jar:1.0.0: Failed to collect dependencies for [junit:junit:jar:RELEASE (test), groupId:project1:jar:1.0.0 (compile), groupId:project1:jar:tests:1.0.0 (test)]: Failed to read artifact descriptor for groupId:project1:jar:1.0.0: Failure to find groupId:parent:pom:1.0.0 in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
    Pourtant si je regarde dans le dossier target du projet 1, j'ai bien les "project1-1.0.0.jar" + "project1-1.0.0-tests.jar" (j'ai bien rebuildé le projet 1 avant le 2, avec un clean avant). Si j'ai bien compris, il cherche les infos au mauvais endroit, c'est ça ?

  5. #5
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Points : 7 275
    Points
    7 275
    Par défaut
    Tu as du faire un "mvn package", c'est ça ?

    Il faut faire un "mvn install". En gros, Maven va packager ton application (créer les .jar), puis les installer dans ton repository local. C'est là où Maven va toujours chercher les dépendances.

  6. #6
    Expert éminent
    Avatar de Matthieu Vergne
    Homme Profil pro
    Consultant IT, chercheur IA indépendant
    Inscrit en
    Novembre 2011
    Messages
    2 270
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant IT, chercheur IA indépendant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2 270
    Points : 7 792
    Points
    7 792
    Billets dans le blog
    3
    Par défaut
    Génial ça marche, merci {^_^}b.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] Utiliser une classe dans un autre projet
    Par noftal dans le forum VB.NET
    Réponses: 10
    Dernier message: 12/11/2013, 17h22
  2. Réponses: 8
    Dernier message: 13/01/2012, 11h47
  3. compile avec JBuilder - classe dans jar
    Par vpovpo dans le forum JBuilder
    Réponses: 1
    Dernier message: 20/02/2009, 17h43
  4. Wascana, utilisation de classe dans un autre projet
    Par BugBunny dans le forum Eclipse C & C++
    Réponses: 0
    Dernier message: 04/10/2008, 12h07
  5. Réponses: 9
    Dernier message: 25/09/2005, 16h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo