我目前正在使用java注释处理来生成大量代码(20秒),当我运行mvn process-resources
时,它只会触发一次,但是当我使用mvn package
时,{{1}战争打包后,或mvn jetty:run
再次被触发。有没有办法强制只运行一次?
我的pom.xml中有个人资料
mvn gwt:run
和maven-source-plugin配置为'jar-no-fork'(这有助于在正常运行mvn时删除一次)
<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>
这是在运行“mvn clean package gwt:run”
时在控制台中输出的 <plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
----------------------- solution -------------------- ---
添加“套餐”个人资料
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
***********************************************************
使用“mvn clean gwt:run -Ppackage”代替“mvn clean package gwt:run”
答案 0 :(得分:1)
您执行的命令是mvn clean package gwt:run
。 Maven执行clean
生命周期(默认情况下为clean:clean目标)。然后它执行package
,它运行绑定到包阶段的所有目标以及绑定到先前阶段的所有目标(生成源,流程源,流程资源等)。最后,它执行gwt:run
目标。如果您查看run
目标的documentation,则有一条非常重要的内容:
在执行生命周期阶段之前调用生命周期阶段的执行。
这意味着Maven将再次运行绑定到process-classes
阶段和所有早期阶段的所有目标。 apt插件执行绑定到generate-sources
阶段,所以它们重复,资源,资源,编译器:编译和exec:exec都重复,因为它们都绑定到process-classes
或之前。
考虑到这一点:mvn clean gwt:run
是否有效?我知道mvn clean jetty:run
可以正常工作而不会重复执行,但我之前没有使用gwt。