2016-09-20 10 views
-1

私はいくつかのバイナリを生成する必要があるmavenプロジェクトを持っています。それらのうちのいくつかは依存関係を持たず、依存関係はバイナリごとに異なる場合があります。Mavenプロジェクトの複数のバイナリに対する依存関係の違い

質問は次のとおりです。どのようにすべての依存関係を含むことなく、すべての瓶に必要なものだけを含めることでこれを達成できますか?

現在、すべてのjarファイルにすべての依存関係を置くことを除いて、ジョブを実行するアセンブリプラグインを使用しています。さらに、私は必要のない標準のapp1-snapshot jarを作成します。どうすればそれを取り除くことができますか?

マイポンポンファイル:

<?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> 

    <groupId>antlrtest</groupId> 
    <artifactId>app1</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>thf_test</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>parsers.THF_test</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/THF_test</finalName> 
         </configuration> 
        </execution> 
        <execution> 
         <id>hmf_test</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>parsers.HMF_test</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/HMF_test</finalName> 
         </configuration> 
        </execution> 
        <execution> 
         <id>HMF_to_THF</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>transformation.HMF_to_THF</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/HMF_to_THF</finalName> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <!-- antlr --> 
      <plugin> 
       <groupId>org.antlr</groupId> 
       <artifactId>antlr4-maven-plugin</artifactId> 
       <version>4.5</version> 
       <configuration> 
        <arguments> 
         <argument>-package</argument> 
         <argument>parsers</argument> 
        </arguments> 
       </configuration> 
       <executions> 
        <execution> 
         <id>antlr</id> 
         <goals> 
          <goal>antlr4</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4-runtime</artifactId> 
      <version>4.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4-maven-plugin</artifactId> 
      <version>4.5</version> 
      <type>maven-plugin</type> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

</project> 
+0

http://stackoverflow.com/questions/2424015/maven-best-practice-for-generating-multiple-jars-with-different-filtered-classesに関連する(しかし重複しない) – YMomb

答えて

0

としてはhttps://stackoverflow.com/a/2426271/800413で説明したが、それは多くの場合、同じプロジェクトから複数のアーティファクト/バイナリを生成するために悪い習慣です。

あなたのケースでは、プロジェクトごとに適切なライブラリを使用して、必要なバイナリを生成し、依存関係としてメインコードベースを共有しているのはなぜですか?

+0

うーん、私はそれを行うことができる。 1つのコマンドで複数のmvnプロジェクトを同時にビルドするオプションはありますか?この場合、libディレクトリにはいくつかのライブラリ(例えばjar)があり、binディレクトリにはいくつかのバイナリがあるはずです。 – Waschbaer

+0

メインプロジェクトとモジュールがある場所で、マルチプロジェクト構造を作成することができます。メインプロジェクトレベルでコマンドを呼び出すときは、これはすべてのサブプロジェクトに適用されるので、1つの 'mvn package'コマンドでたくさんのprojetcsを構築できます – YMomb

関連する問題