2016-10-01 4 views
1

ich eine Multimodul Maven Anwendung, die Frühlings-Boot verwendet:Federschuh-Test Multimodul Maven Anwendung

- spring boot parent 
    - myproject parent (both parent and module pom) 
     - module1 
     - module2 
     - module-it (integration tests) 

In meinem Modul-it, füge ich die anderen Module in meiner Abhängigkeiten und ich konfigurieren Maven-failsafe- Plugin wie folgt:

<build> 
    <plugins> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

Wenn ich mein Projekt mit maven bauen, bekomme ich "Build Success":

mvn clean install 

So weit so gut.
Dennoch möchte ich, dass jedes meiner Module am Ende des Builds ein ausführbares Glas ist. Mit den obigen Einstellungen ist das Manifest nicht definiert und das Jar ist nicht ausführbar. um dieses Problem zu beheben, habe ich die folgenden in meinem module1 und Module2 pom-Dateien hinzugefügt:

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <goals> 
       <goal>repackage</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

Mit dieser Einstellung meiner JAR-Datei ausführbar ist, aber ich kann nicht mehr bauen. Klassen, die ich in meinem Modul verwende, werden nicht gefunden.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project module-it: Compilation failure: Compilation failure: 
[ERROR] /home/user/<path-to-project>/testing/module-it/src/test/java/com/mycompany/testing/greeting/GreetingControllerIT.java:[20,17] cannot find symbol 
[ERROR] symbol: class GreetingController 
[ERROR] location: class com.mycompany.testing.greeting.GreetingControllerIT 
[ERROR] /home/user/<path-to-project>/testing/module-it/src/test/java/com/mycompany/testing/hello/HelloControllerIT.java:[20,17] cannot find symbol 
[ERROR] symbol: class HelloController 
[ERROR] location: class com.mycompany.testing.hello.HelloControllerIT 
[ERROR] /home/user/<path-to-project>/testing/module-it/src/test/java/com/mycompany/testing/greeting/GreetingControllerIT.java:[16,27] cannot find symbol 
[ERROR] symbol: class GreetingController 
[ERROR] /home/user/<path-to-project>/testing/module-it/src/test/java/com/mycompany/testing/hello/HelloControllerIT.java:[16,27] cannot find symbol 
[ERROR] symbol: class HelloController 

Meine Tests haben die folgende Form (idem für HelloControllerIT.java):

@RunWith(SpringRunner.class) 
@SpringBootTest(classes = GreetingController.class) 
public class GreetingControllerIT { 

    @Autowired 
    private GreetingController greetingController; 

    @Test 
    public void getIT_OK() throws Exception { 

     Assert.assertEquals("My greetings", greetingController.getStr()); 
    } 
} 

Und die Controller haben diese Form (die getstr() -Methode ist hier nur die Konfiguration zu testen):

Können Sie mir bitte helfen zu verstehen, warum Spring-Boot-Maven-Plugin mein Build scheitern lässt und wie ich das Problem lösen kann?

Ich bin mir dessen bewusst:

  • meine Tests sind nicht Integrationstests für jetzt. Es ist nur ein Beispiel;
  • Laut den Antworten, die ich auf Stackoverflow gefunden habe, könnte ich eine Datei wie die unten stehende hinzufügen und dann @ContextConfiguration verwenden, aber ich habe versucht und es ändert sich nicht die Ausgabe von Maven Build.
@Configuration 
@ComponentScan(basePackages = "com.mycompany.testing") 
public class AppConfig { 
} 

Vielen Dank im Voraus für Ihre Hilfe.

Antwort

4

um dieses Problem zu lösen, haben wir ein Klassifikator in der Dokumentation, wie custom repackage classifier

Das Plugin wird dann hinzufügen:

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <goals> 
       <goal>repackage</goal> 
      </goals> 
      <configuration> 
       <classifier>exec</classifier> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
Verwandte Themen