ebean-orm-tools / ebean-gradle-plugin

Plugin that performs Enhancement (entity, transactional, query bean) and can generate query beans from entity beans written in Kotlin via kapt
Apache License 2.0
10 stars 12 forks source link

Enhancement doesn't work anymore with gradle build cache #22

Closed Keltas359 closed 5 years ago

Keltas359 commented 5 years ago

Until now I regularly postponed updating to a later version of ebean-gradle-plugin than 11.11.1, since it seemed to break the enhancement. Now I finally got the time to narrow down the issue and discovered that my issue seems to be related to the gradle build cache.

It can be easily reproduced with the "example-gradle-kotlin" project:

  1. In the root directory create a "gradle.properties" and add the line "org.gradle.caching=true"
  2. Run ./gradlew clean test

On the first build it will still show the "ebean-enhance" messages:

> > Task :classes
ebean-enhance> cls: org/example/domain/Customer  msg: enhanced
ebean-enhance> cls: org/example/domain/OrderLine  msg: enhanced
ebean-enhance> cls: org/example/domain/Order  msg: enhanced
ebean-enhance> cls: org/example/domain/Product  msg: enhanced
ebean-enhance> cls: org/example/domain/BaseModel  msg: enhanced

> Task :test

On consecutive builds the enhancement isn't triggered anymore and a BeanNotEnhancedException is thrown :

Build cache is an incubating feature.

> Task :test FAILED

org.example.domain.CustomerTest > save STANDARD_OUT
    10:59:30.752 [Test worker] INFO  io.ebean.EbeanVersion - ebean version: 11.32.1
    10:59:30.812 [Test worker] INFO  i.e.config.properties.LoadContext - loaded properties from [application-test.yaml]
    10:59:30.848 [ForkJoinPool.commonPool-worker-2] INFO  io.ebean.test.config.platform.Config - Using jdbc settings - username:sa url:jdbc:h2:mem:mykt_app driver:org.h2.Driver
    10:59:30.860 [Test worker] INFO  i.e.t.c.provider.ProviderAutoConfig - for testing purposes a current user and tenant provider has been configured. Use io.ebean.test.UserContext to set current user and tenant in tests.
    10:59:30.916 [Test worker] INFO  i.e.datasource.pool.ConnectionPool - DataSourcePool [db] autoCommit[false] transIsolation[READ_COMMITTED] min[2] max[200]
    10:59:31.077 [Test worker] INFO  io.ebean.internal.DefaultContainer - DatabasePlatform name:db platform:h2

org.example.domain.CustomerTest > save FAILED
    java.lang.ExceptionInInitializerError
        at io.ebean.Model.db(Model.java:114)
        at io.ebean.Model.save(Model.java:188)
        at org.example.domain.CustomerTest.setup(CustomerTest.kt:39)
        at org.example.domain.CustomerTest.save(CustomerTest.kt:14)

        Caused by:
        io.ebean.config.BeanNotEnhancedException: Bean class org.example.domain.OrderLine is not enhanced? Check packages specified in ebean.mf. If you are running in IDEA or Eclipse check that the enhancement plugin is installed. See https://ebean.io/docs/trouble-shooting#not-enhanced

If you run the build again with "./gradlew clean test --no-build-cache" the enhancement is triggered again and the tests pass:


./gradlew clean test --no-build-cache

> Task :classes
ebean-enhance> cls: org/example/domain/Customer  msg: enhanced
ebean-enhance> cls: org/example/domain/OrderLine  msg: enhanced
ebean-enhance> cls: org/example/domain/Order  msg: enhanced
ebean-enhance> cls: org/example/domain/Product  msg: enhanced
ebean-enhance> cls: org/example/domain/BaseModel  msg: enhanced

> Task :test

The last version of the plugin where the enhancements are still working seems to be "11.12.1". With any later version I get the enhancement exceptions.