2

私は現在、Javaアノテーション処理を使用して多くのコード(20秒)を生成しています。実行mvn process-resourcesすると、aptは1回だけトリガーされますが、を使用するmvn packageと、mvn jetty:runまたはmvn gwt:run戦争がパッケージ化された後にaptが再度トリガーされます。aptを1回だけ実行するように強制する方法はありますか?

pom.xmlにプロファイルがあります

<profile>
    <id>codegen</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <exists>src/main/resources/META-INF</exists>
        </file>
    </activation>
    <dependencies>
        <dependency>
            <groupId>com.regulationworks.core.code-gen</groupId>
            <artifactId>executor</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.0.5</version>
                <executions>
                    <execution>
                        <id>generate-jpa-metamodel</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <processors>
                                <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                            </processors>
                            <outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-gwt-jpa-proxies</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <processors>
                                <processor>org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor</processor>
                            </processors>
                            <outputDirectory>${project.build.directory}/generated-sources/entity-proxies</outputDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>code-gen-executor</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <processors>
                                <processor>com.regulationworks.core.gwt.codegen.CodeGenExecutor</processor>
                            </processors>

                            <options>
                                <generateRequestFactory>${core.codegen.requestfactory}</generateRequestFactory>
                                <generateMappingXml>${core.codegen.xmlmapping}</generateMappingXml>
                                <codegen.scaffold>${codegen.scaffold}</codegen.scaffold>
                                <codegen.scaffold.override>${codegen.scaffold.override}</codegen.scaffold.override>
                                <codegen.scaffold.classes>${codegen.scaffold.classes}</codegen.scaffold.classes>
                                <codegen.commands.class.name>${codegen.commands.class.name}</codegen.commands.class.name>
                            </options>
                        </configuration>
                    </execution>
                    <!--<execution>
                               <id>generate-gwt-rf</id>
                               <goals>
                                   <goal>process</goal>
                               </goals>
                               <phase>process-classes</phase>
                               <configuration>
                                   <processors>
                                       <processor>com.google.web.bindery.requestfactory.apt.RfValidator</processor>
                                   </processors>
                                   <options>
                                   <rootOverride>${core.codegen.rfvalidate}</rootOverride>
                                   </options>
                                   <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                               </configuration>
                           </execution>-->
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <configuration>
                            <id>VerifyRequestFactoryInterfaces</id>
                            <executable>java</executable>
                            <arguments>
                                <argument>-cp</argument>
                                <classpath />
                                <argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
                                <argument>${project.build.outputDirectory}</argument>
                                <argument>${core.codegen.rfvalidate}</argument>
                            </arguments>
                            <skip>${core.codegen.rfvalidate}</skip>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</profile>

およびmaven-source-pluginが「jar-no-fork」に構成されている(これは、通常のmvn installを実行するときに1回削除するのに役立ちました)

    <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.1.2</version>
        <executions>
            <execution>
                <goals>
                    <goal>jar-no-fork</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

「mvncleanpackagegwt:run」を実行すると、コンソールに出力されます。

X:\workspace\Decision\decision-app>mvn clean package gwt:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building DecisionWorks App 2.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.opensaml:opensaml:jar:1.1b is missing, no dependency information available
[WARNING] The POM for net.sf.saxon:saxon-dom:jar:8.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ decision-app ---
[INFO] Deleting X:\workspace\Decision\decision-app\target
[INFO]
***********************************************************
 This is where apt executed first time which look right
***********************************************************
[INFO] --- maven-processor-plugin:2.0.5:process (generate-jpa-metamodel) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\metamodel added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\metamodel
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.0.0.Final
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-gwt-jpa-proxies) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 3.7.0-SNAPSHOT
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (code-gen-executor) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\apt added
[INFO] Adding compiler arg: -Acodegen.scaffold.override=true
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -Acodegen.scaffold.override=true
[INFO] javac option: -processor
[INFO] javac option: com.regulationworks.core.gwt.codegen.CodeGenExecutor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\apt
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ decision-app ---
[INFO] Compiling 260 source files to X:\workspace\Decision\decision-app\target\classes
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) @ decision-app ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 3 resources
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ decision-app ---
[INFO] Compiling 3 source files to X:\workspace\Decision\decision-app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.9:test (default-test) @ decision-app ---
[INFO] Surefire report directory: X:\workspace\Decision\decision-app\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.172 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ decision-app ---
[INFO] Packaging webapp
[INFO] Assembling webapp [decision-app] in [X:\workspace\Decision\decision-app\target\decision]
[INFO] Processing war project
[INFO] Copying webapp webResources [X:\workspace\Decision\decision-app\target] to [X:\workspace\Decision\decision-app\target\decision]
[INFO] Copying webapp webResources [X:\workspace\Decision\decision-app\src/main/webapp/WEB-INF] to [X:\workspace\Decision\decision-app\target\decision]
[INFO] Copying webapp resources [X:\workspace\Decision\decision-app\src\main\webapp]
[INFO] Processing overlay [ id com.regulationworks.core:document-cmis-plugin-config]
[INFO] Webapp assembled in [10118 msecs]
[INFO] Building war: X:\workspace\Decision\decision-app\target\decision.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO]
[INFO] --- maven-source-plugin:2.1.2:jar-no-fork (default) @ decision-app ---
[INFO]
[INFO] >>> gwt-maven-plugin:2.3.0:run (default-cli) @ decision-app >>>
***********************************************************
This is where apt executed second time which is a waste of time
***********************************************************
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-jpa-metamodel) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\metamodel added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\metamodel
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.0.0.Final
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (generate-gwt-jpa-proxies) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies added
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: org.hibernate.gwtmodelgen.GwtProxyModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\entity-proxies
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 3.7.0-SNAPSHOT
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (code-gen-executor) @ decision-app ---
[INFO] Source directory: X:\workspace\Decision\decision-app\target\generated-sources\apt added
[INFO] Adding compiler arg: -Acodegen.scaffold.override=true
[INFO] javac option: -cp
[INFO] javac option: ...
[INFO] javac option: -proc:only
[INFO] javac option: -Acodegen.scaffold.override=true
[INFO] javac option: -processor
[INFO] javac option: com.regulationworks.core.gwt.codegen.CodeGenExecutor
[INFO] javac option: -d
[INFO] javac option: X:\workspace\Decision\decision-app\target\classes
[INFO] javac option: -s
[INFO] javac option: X:\workspace\Decision\decision-app\target\generated-sources\apt
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ decision-app ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] Copying 17 resources
[INFO] Copying 80 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ decision-app ---
[INFO] Compiling 60 source files to X:\workspace\Decision\decision-app\target\classes
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) @ decision-app ---
[INFO]
[INFO] <<< gwt-maven-plugin:2.3.0:run (default-cli) @ decision-app <<<
[INFO]
[INFO] --- gwt-maven-plugin:2.3.0:run (default-cli) @ decision-app ---
***********************************************************
finally be able to start the web app, 30 seconds wasted for second apt execution
***********************************************************

- - - - - - - - - - - - 解決 - - - - - - - - - - - -

  1. 「パッケージ」プロファイルを追加する

    <profile>
        <id>package</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <packagingExcludes>WEB-INF/lib/*-sources.jar, WEB-INF/lib/gwt-user-*.jar</packagingExcludes>
                        <webResources>
                            <resource>
                                <directory>src/main/webapp/WEB-INF</directory>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>**/*.xml</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </webResources>
                    </configuration>
                    <executions>
                        <execution>
                            <id>explode-war</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>exploded</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    
  2. 「mvncleanpackagegwt:run」の代わりに「mvnclean gwt:run-Ppackage」を使用します

4

1 に答える 1

1

実行したコマンドはですmvn clean package gwt:run。Mavenはcleanライフサイクルを実行します(デフォルトではclean:cleanゴール)。次に、packageを実行します。これは、パッケージフェーズにバインドされたすべてのゴールと、前のフェーズ(生成ソース、プロセスソース、プロセスリソースなど)にバインドされたすべてのゴールを実行します。最後に、gwt:runゴールを実行します。目標のドキュメントを見ると、非常に重要な行が1つあります。run

ライフサイクルフェーズのプロセスクラスの実行を呼び出してから、それ自体を実行します。

これは、Mavenがフェーズにバインドされたすべてのゴールprocess-classesと以前のすべてのフェーズを再度実行することを意味します。aptプラグインの実行はgenerate-sourcesフェーズにバインドされるため、resources:resources、compiler:compile、およびexec:execがすべてバインドされているprocess-classesか、以前にバインドされているため、繰り返し実行されます。

それを念頭に置いて:動作しmvn clean gwt:runますか?mvn clean jetty:run実行を複製しなくても期待どおりに機能することはわかっていますが、これまでgwtを使用したことはありません。

于 2012-06-06T15:58:43.523 に答える