3

我有两个 Java 主类,需要在构建过程的不同部分执行。generate-sources在此阶段,作为我的标准构建过程的一部分,需要始终执行。另一个需要作为配置文件的一部分执行,但该配置文件应在阶段结束时执行,该process-classes阶段还应包括generate-sources之前的阶段。

generate-sources在标准构建过程的阶段,我能够让第一个插件正常工作:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.example.MySourceGenerator</mainClass>
                </configuration>
            </plugin>

但是,当我将同一插件的第二个实例添加到配置文件时,在我的构建过程中不再调用作为标准构建的一部分定义的插件,从而导致编译错误。这是配置文件中的配置:

<profiles>
        <profile>
            <id>initSchema</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>com.example.SomeOtherClass</mainClass>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

这是我在命令行上运行的:mvn process-classes -PinitSchema. 我的配置有什么问题?我期待这两个插件在各自的阶段执行。

澄清一下:第一个 exec-maven-plugin 生成源,第二个初始化我的数据库模式。

编辑:这是输出

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building ABC Web Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) @ web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/msg added.
[INFO] 
[INFO] --- maven-processor-plugin:2.0.6:process (process) @ web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt added
[INFO] javac option: -cp
...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: com.company.vocab.generator.VocabAnnotationProcessor,org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] javac option: -s
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.2.0.Final
[INFO] diagnostic /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/AccountDto.java:5: error: cannot find symbol
import com.telos.xacta.util.Messages;
...
(more similar messages)
[INFO] 
[INFO] --- jaxb2-maven-plugin:1.5:xjc (default) @ web-app ---
[INFO] Generating source...
[INFO] parsing a schema...
[INFO] compiling a schema...
...
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ web-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 16 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ web-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 281 source files to /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] -------------------------------------------------------------
...
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/ProjectHeadDto.java:[4,28] cannot find symbol
  symbol:   class Messages
  location: package com.company.util
...
(more similar errors)
...
[INFO] 29 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.817s
[INFO] Finished at: Thu Aug 01 20:49:07 EDT 2013
[INFO] Final Memory: 31M/282M
[INFO] ------------------------------------------------------------------------
4

1 回答 1

0

给两个执行块一个不同的 id,因为现在它们都使用默认 id,所以一个会覆盖另一个。

于 2013-08-01T20:35:30.397 回答