5

I've been using Avaje.org ebean ORM layer for a while, but I don't understand how to enable the byte-code enhancement functionality described in the "Ebean v2.6.0 User Guide" with Maven.

I found a configuration example on the Avaje.org homepage, but it doesn't work. Neither does the demo Maven boilerplate on GitHub.

Help!

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
JBCP
  • 13,109
  • 9
  • 73
  • 111

3 Answers3

7

EBeans now has its own Maven Plugin, but I can't find any documentation online, so here is an example of how to use it:

<plugin>
    <groupId>org.avaje.ebeanorm</groupId>
    <artifactId>avaje-ebeanorm-mavenenhancer</artifactId>
    <version>${ebean.version}</version>
    <executions>
        <execution>
            <id>main</id>
            <phase>process-classes</phase>
            <goals>
                <goal>enhance</goal>
            </goals>
            <configuration>
                <packages>com.package1.**,com.package2.**</packages>
                <transformArgs>debug=1</transformArgs>
                <classSource>${project.build.outputDirectory}</classSource>
                <classDestination>${project.build.outputDirectory}</classDestination>
            </configuration>
        </execution>
    </executions>
</plugin>

With Eclipse

If you use Eclipse, you will want to make sure it runs the plugin when needed, like this:

<build>
    <plugins>
        <!-- plugins here -->
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.avaje.ebeanorm</groupId>
                                    <artifactId>avaje-ebeanorm-mavenenhancer</artifactId>
                                    <versionRange>[3.3.2,)</versionRange>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnConfiguration>true</runOnConfiguration>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
JBCP
  • 13,109
  • 9
  • 73
  • 111
  • works for me... but i had to put executions inside configuration. – joshua Jul 27 '13 at 06:20
  • 1
    When I use m2e in Eclipse the compilation works, and it runs. But m2e complains "Plugin execution not covered by lifecycle configuration: org.avaje.ebeanorm:avaje-ebeanorm-mavenenhance." Anyone know how to fix this? – Robb Hoff Oct 24 '14 at 16:13
  • @area5one - funny that you asked, I JUST updated the answer with exactly what you need. – JBCP Oct 24 '14 at 16:16
  • 1
    wow nice one, I couldn't seem to get it though, does ... go inside the tag? Does the order matter? – Robb Hoff Oct 24 '14 at 16:41
  • 1
    I forget if order matters, I have it immediately below the block, inside . I'll update the answer to show it... – JBCP Oct 24 '14 at 16:52
  • 1
    Hi, I managed it! Order doesn't matter, the ... can be both before or after ..., my specific problem was that I had omitted the configuration. Also I'm using org.avaje.ebeanorm version 4.1.8. so replaced that in your answer – Robb Hoff Oct 24 '14 at 16:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63609/discussion-between-area5one-and-jbcp). – Robb Hoff Oct 24 '14 at 20:09
2

OBSOLETE ANSWER

This answer is for a very old version of EBeans, please disregard it.

Original Content

The example on the Avaje page has some mistakes.

  1. The 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 block.

JBCP
  • 13,109
  • 9
  • 73
  • 111
  • Answer also available in blog form here: http://teamflawless.org/2012/using-maven-to-enable-ebean-enhancement/ – JBCP Aug 16 '12 at 23:14
2

JBCP's answer is for old ebean version (org.avaje.ebeanorm). For newer version (io.ebean) you need to change to ebean-maven-plugin.

<plugin>
    <groupId>io.ebean</groupId>
    <artifactId>ebean-maven-plugin</artifactId>
    <version>${ebean.version}</version>
    <executions>
        <execution>
            <id>main</id>
            <phase>process-classes</phase>
            <goals>
                <goal>enhance</goal>
            </goals>
            <configuration>
                <packages>com.package1.**,com.package2.**</packages>
                <transformArgs>debug=1</transformArgs>
                <classSource>${project.build.outputDirectory}</classSource>
                <classDestination>${project.build.outputDirectory}</classDestination>
            </configuration>
        </execution>
    </executions>
</plugin>

Note: ebean plugin version should be the same as ebean version.

Reference: Maven Repo, Github

thangdc94
  • 1,542
  • 2
  • 26
  • 38