2017-11-03 10 views
3

実行時にCode Generate.javaによって生成されるクラスをコンパイルしようとしています。私はexec-maven-pluginによって実行時にGenerate.javaを正常に実行することができました。これはgenerated-source-javaでコードを生成しています。しかし、このコードはコンパイルされていません。私は同じものを一つのjarファイルに追加したいのですが、maven-assembly-pluginを使っています。
ここにpomスナップショットがあります。実行時に生成されるJavaファイルをコンパイルする方法

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.5.0</version> 
    <executions> 
     <execution> 
     <id>build-test-environment</id> 
     <phase>generate-test-resources</phase> 
     <goals> 
     <goal>java</goal> 
     </goals> 
    </execution> 
    </executions> 
    <configuration> 
     <mainClass>com.test.Generate</mainClass> 
    </configuration> 
    </plugin> 
    <plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <executions> 
     <execution> 
     <phase>prepare-package</phase> 
     <goals> 
      <goal>add-source</goal> 
     </goals> 
     <configuration> 
      <sources> 
      <source>${project.build.directory}/generated-sources-java</source> 
      </sources> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
    <plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <finalName>test</finalName> 
     <descriptorRefs> 
     <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <appendAssemblyId>false</appendAssemblyId> 
    </configuration> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

答えて

1

あなたは近くです。プラグインは異なるフェーズにバインドする必要があります。現時点では、prepare-packageフェーズで新しいソースディレクトリが追加されています。これは、すべての組み込みコンパイルが完了した後に発生します。ライフサイクルの早い段階で実行するように設定すると、すべてが「うまくいく」と思います。

テストコードを操作するための相

は、次のとおり

  • 生成するテスト・ソースを
  • プロセステスト源
  • 生成するテスト資源
  • プロセステストリソース
  • テストコンパイル

このケースでは、示すように設定:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.5.0</version> 
    <executions> 
    <execution> 
     <id>build-test-environment</id> 
     <phase>generate-test-sources</phase> <!-- generating source code --> 
     <!-- rest of config --> 
    </execution> 
    </executions> 
     <!-- rest of config, consider moving into specific execution --> 
</plugin> 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <executions> 
    <execution> 
     <id>add-test-sources</id> 
     <phase>process-test-sources</phase> <!-- do something with generated test sources --> 
     <goals> 
     <goal>add-test-source</goal> 
     </goals> 
     <!-- rest of config --> 
    </execution> 
</executions> 
私は( add-test-sourceに)あまりにも build-helper-maven-plugin目標を変更し

注、これは我々が扱っているテストコードであるため。

詳細はMaven Lifecycle概要文書を参照してください。

+0

私はそれを試して、それは動作していません。私の現在のpomは生成されたコードを.java拡張子でコピーしているのに対し、ターゲット/クラスにコードをコピーすることさえできません。 –

+0

上記の設定と同じ設定を使用しましたが、フェーズのみが変更されましたか?私はすべての既存の設定を再入力しませんでした。はいと仮定すると、次のステップは、デバッグオプション( '-X')を設定してMavenを実行し、コンパイラプラグインがテストソースを探している場所を確認することです。次に、プラグインを設定して、それぞれの宛先がチェーン内の次のソースになるようにします。 – user944849

関連する問題