Using Maven to Enable Ebean Enhancement

I’ve been using Avaje.org Ebean ORM layer for a while, but I haven’t bothered to enable the bytecode enhancement until now. When I searched for how to enable this enhance I found a configuration example on the Avaje.org homepage, but it doesn’t work, due to some problems in the plugin configuration. The demo project on GitHub has the same problems.

Luckily, I know Maven pretty well. 🙂

The example on the Avaje page has some mistakes.

  1. The <phase> tag is incorrect: ‘process-ebean-enhancement’ is not a Maven lifecycle, so the plugin in the example configuration won’t run correctly. The correct phase is ‘process-classes’.
  2. The ‘classSource’ parameter is incorrect. As configured, the ebean plugin would enhance @Entity clases in your test code, rather than you production code. The correct value is ‘${project.build.outputDirectory}’.
  3. Make sure to update the package-space for your project. This is ‘com.mycompany.**’ in the example below.

The complete config should be:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>process-ebean-enhancement</id>
            <phase>process-classes</phase>
            <configuration>
                <tasks>
                    <property name="compile_classpath" refid="maven.compile.classpath" />
                    <echo message="------ Ebean enhancing test classes debug level ------" />
                    <echo message="Classpath: ${compile_classpath}" />
                    <taskdef name="ebeanEnhance" 
                        classname="com.avaje.ebean.enhance.ant.AntEnhanceTask"
                        classpath="${compile_classpath}" />
                    <ebeanEnhance classSource="${project.build.outputDirectory}" 
                        packages="com.mycompany.**" transformArgs="debug=1" />
                </tasks>
                <encoding>UTF-8</encoding>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will enhance all of the @Entity classes in the “src/main/java/com/mycompany” and below.

You can improve execution time by being more restrictive on the packages to examine.

Also, you may need to duplicate this config if you do need to enhance test classes. In that case, use the ‘proces-test-classes’ phase for a second <configuration> block.



Leave a Reply

Your email address will not be published. Required fields are marked *