2016-07-05 2 views
2

Ich habe zwei Maven-Profile P1 und P2 und was ich tun möchte ist, dass abhängig von dem Profil, das ich für mein Projekt verwende, bestimmte Ressourcen ausgeschlossen werden sollten.Ist es möglich, Klassen oder Ressourcen pro Profil in Maven auszuschließen (oder einzuschließen)?

Zum Beispiel

<profiles> 
    <profile> 
     <id>P1</id> 
     <properties> 
      <app.home>Path to project home</app.home> 
      <exclude>src/main/java/foo/*.*</exclude> <!-- need to exclude all files in src/main/java/foo in this profile --> 
     </properties> 
    </profile> 
    <profile> 
     <id>P2</id> 
     <properties> 
      <app.home>Path to project home</app.home> 
      <exclude>src/main/java/bar/*.*</exclude> <!-- need to exclude all files in src/main/java/bar in this profile--> 
     </properties> 
    </profile> 
</profiles> 

Also, hier, was ich tun möchte, ist es, alle Dateien in src/main/java ausschließen/foo /, wenn ich das P1 Profil bauen mit und schließen alle Dateien in src/main/java/bar, wenn ich mit dem P2-Profil baue.

Ist das möglich und wenn nicht gibt es eine Alternative?

+0

Sie sollten zwei separate Module verwenden, was bedeutet, ein Multi-Modul aufbauen zu müssen. Denn dies ist eine Verletzung der Trennung von Bedenken. – khmarbaise

Antwort

2

Sie können eine build mit dem Maven Compiler Plugin zu Ihrem Profil hinzufügen und fügen Sie ein exclude dort

Z.B.

<profile> 
    <id>P1</id> 
    <properties> 
     <app.home>Path to project home</app.home> 
    </properties> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
       <excludes> 
        <exclude>**src/main/java/foo/*.*</exclude> 
       </excludes> 
      </configuration> 
     </plugin> 
    </plugins> 
</profile> 

Für weitere Informationen siehe Maven: excluding java files in compilation

Verwandte Themen