2

I have a section in my pom.xml that generates OpenJPA's metamodel like this:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>  
    <executions>
        <execution>
            <id>generate-entity-metamodel</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>
                    compile
                </goal>
            </goals>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <optimize>true</optimize>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <proc>only</proc>
                <compilerArgument>-Aopenjpa.metamodel=true</compilerArgument>
                <generatedSourcesDirectory>${project.build.directory}/generated-sources/openjpa-metamodel</generatedSourcesDirectory>
            </configuration>
        </execution>
        <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The "problem" I have is that this "default" execution of maven-compiler-plugin is called only when there is a change in source code - which is expected, but "generate-entity-metamodel" is called always which leads to failure in build since those generate classes already exist from a previous build. I have always to do mvn clean compile in order for my build to succeed.

How can I fix this and have "generate-entity-metamodel" called only when there were changes in source files?


Here's the output when I do mvn test
[INFO] --- build-helper-maven-plugin:1.8:add-source (default) @ icmynet-core ---
[INFO] Source directory: E:\Projekti\release-repo\icmynet\trunk\icmynet-core\target\generated-sources\openjpa-metamodel added.
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (generate-entity-metamodel) @ icmynet-core ---
[INFO] Changes detected - recompiling the module!

Hm... why are there "changes detected"?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Rade_303
  • 905
  • 11
  • 28
  • Hm, maybe I've hit http://stackoverflow.com/questions/17944108/? – Rade_303 Mar 04 '14 at 14:52
  • Everywhere I've worked over the last decade has used `mvn clean install` when using maven. The IDE is the only place incremental builds are allowed. – Software Engineer Mar 04 '14 at 16:14
  • 2
    This is not really what I looked for. Why only IDEs would be allowed to do incremental builds? Why is it wrong to wish to cut on the build time? – Rade_303 Mar 07 '14 at 10:54
  • 1
    It's not wrong to cut the build time, but IDEs do incremental compilation by default, so we don't really need maven to do it too. We use maven for something else -- to ensure that everything really builds and that all tests run correctly. – Software Engineer Mar 07 '14 at 15:39
  • 1
    Almost 8 years later and only a little wiser I don't find the comment above satisfactory. If `clean` was something mandatory, then why extract it as a separate lifecycle, which is not mandatory nevertheless. There was really some type of a problem with how Maven and OpenJPA Maven plugin did their stuff back in the day. But since I moved on to other projects. – Rade_303 Feb 15 '22 at 00:12

0 Answers0