20

私はm2eclipseを 2 年ほど使用しており、現在はm2eに切り替えています。

残念ながら、これは私にとっていくつかの機能を壊してしまいました。

多くのプロジェクトで、私は Java コードを生成してきましたが、通常はライブラリ プロジェクトのメイン クラスを介して生成されます。典型的なセットアップは次のとおりです。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>generateDTOs</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>java</goal>
            </goals>
            <configuration>
                <classpathScope>test</classpathScope>
                <mainClass>com.somecompany.SomeCodeGenerator</mainClass>
                <arguments>
                    <argument>${project.build.directory}/generated-sources/foo</argument>
                    <argument>${project.basedir}/path/to/a/config/file</argument>
                    <argument>more arguments</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>addDtoSourceFolder</id>
            <goals>
                <goal>add-source</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources/foo</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

以前は、Eclipse を使用してそのプロジェクトを Maven プロジェクトとしてインポートするだけで、コードが自動的に実行され、ソース フォルダーが Eclipse プロジェクトに追加されていました。

これで、m2e は buildhelper プラグイン用の「コネクタ」をインストールしたので、ソース フォルダーが作成されましたが、Run As > Maven > generate-sources. これは本当に面倒です。以前のように、maven ビルドが pom.xml の変更、Project > Clean ...SVN の更新、Eclipse の起動などに応答するようにしたいと考えています。

m2e を m2eclipse のように動作させるにはどうすればよいですか?

4

2 に答える 2

21

Eclipseビルドの一部としてコードジェネレーターを実行しても問題がないことをM2Eに通知する必要があります。

<project>
  <build>
     [...]
     <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence 
          on the Maven build itself. -->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <versionRange>[,)</versionRange>
                    <goals>
                      <goal>java</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute/>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

ノート:

  1. この構成は、プラグインの直下ではなく、pluginManagementセクションに配置することが重要です。
  2. これにより、M2Eは、すべてのEclipseビルドの一部としてPOMで指定されたすべてのJava実行を実行します。これは、それらが頻繁に実行され、遅い場合は大きな迷惑になることを意味します。M2Eにそれらのいくつかを実行させ、他をスキップさせる方法がわかりません。おそらく、不要な実行をプロファイルに配置する必要があります。
于 2011-10-19T19:11:17.010 に答える
1

Eclipse では、デフォルトで空のインポート中に実行されるライフサイクル ステップを定義できます。これを process-resources に変更するか、単に Maven -> Update Project Configuration を実行するだけです。構成 (Windows -> 設定 -> Maven) で、デフォルトの動作を変更してライブを簡素化できます。

于 2011-07-14T10:50:16.640 に答える