3

I have two Java main classes that I need executed during different parts of a build process. One needs to execute ALWAYS as part of my standard build process during the generate-sources phase. The other needs to execute as part of a profile, but that profile should be execute at the end of the process-classes phase, which should also include the generate-sources phase prior to that.

I was able to get the first plugin working correctly during the generate-sources phase of the standard build process:

            <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>

However when I added a second instance of the same plugin to the profile, the plugin defined as part of the standard build is no longer invoked during my build process, resulting in compile errors. This is the configuration in the profile:

<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>

This is what I run on the command line: mvn process-classes -PinitSchema. What is wrong with my configuration? I am expecting both plugins to execute during their respective phases.

To clarify: the first exec-maven-plugin generates sources and the second one initialized my DB schema.

EDIT: Here is the output

[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] ------------------------------------------------------------------------
citress
  • 889
  • 3
  • 13
  • 35
  • Could you please add the output of executing mvn process-classes -PinitSchema on your configuration – mebada Jul 29 '13 at 16:37

1 Answers1

0

Give both the execution blocks a different id, because now they both use the default id and so one will overwrite the other.

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • I tried adding different execution ids to each execution block, but Maven tries to execute "SomeOtherClass" (called in the profile) in the beginning of the generate-sources phase, which is the phase configured for the first execution of the plugin. It dies with a ClassNotFoundException as the class has not been compiled yet. – citress Aug 02 '13 at 01:07
  • The output shows the exec-maven-plugin is never being executed. – Robert Scholte Aug 08 '13 at 08:26
  • There are 2 exec-maven-plugins configured. The first one generates sources for the app, and the second one occurs during process-classes. The problem is that the first one was never executed, and thus the compilation fails. If I do a full build first (mvn clean install), and then execute "mvn process-classes -PinitSchema" without first doing a clean, I encounter no failures. To me this indicates that the second exec-maven-plugin was run successfully even though the first one didn't run. – citress Aug 08 '13 at 13:17