Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PlayFramework + Ebean with Gradle

I'm trying to use the Play Gradle Plugin to compile/package a Play 2.3.x app that uses Ebean.

Everything works fine during compilation and packaging, but when I run the app I get the well known error

Entity type class SomeEntity is not an enhanced entity bean. 
Subclassing is not longer supported in Ebean

So how can I can make Gradle run the enhancer during compilation?

like image 505
Salem Avatar asked Sep 09 '15 11:09

Salem


1 Answers

This is how i have done it. I am using play 2.4 but should be able to work for you.

First add a configuration in your build.gradle as follows -

configurations {
    enhance
}

Next add a dependency on ebeanorm agent as shown below:

dependencies {
    enhance group: 'org.avaje.ebeanorm', name: 'avaje-ebeanorm-agent', version: '4.5.3'
}

Ensure you have the required play dependencies in your build.gradle as shown below:

dependencies {
    play 'org.avaje:avaje-agentloader:2.1.2'
    play "org.avaje.ebeanorm:avaje-ebeanorm-agent:4.5.3"
}

Finally add the following to do the enhancement after the compile task has executed:

model {
    components {
        play {
            binaries.all{binary ->
                tasks.withType(PlatformScalaCompile) {
                    doLast {
                        ant.taskdef(name: 'ebean', classname: 'com.avaje.ebean.enhance.ant.AntEnhanceTask', classpath: project.configurations.enhance.asPath)
                        ant.ebean(classSource: "${project.buildDir}/playBinary/classes", packages: 'models.package.name', transformArgs: 'debug=1')

                    }
                }
            }
        }
    }
like image 121
koolrich Avatar answered Sep 23 '22 02:09

koolrich