title: Hibernate annotation scanning not working under Gradle 5.4
body: <p>I'm busy converting a maven build into a Gradle build, i got everything running, except that i now see this error whenever i try to run an hql query via Hibernate for all entities that i try to query (running via Maven still works, the pom file is still in the project):</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: Account is not mapped [SELECT o FROM Account AS o WHERE lower(o.email)=:email]
  </code></pre>
  
  <p>I have the following dependencies under Maven:</p>
  
  <pre><code>    &lt;dependencies&gt;
  
          ...
  
          &lt;!-- Hibernate --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;cglib&lt;/groupId&gt;
                      &lt;artifactId&gt;cglib&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;dom4j&lt;/groupId&gt;
                      &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
              &lt;version&gt;${hibernate-validator.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-c3p0&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-java8&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          ...
  
  &lt;/dependencies&gt;
  
  </code></pre>
  
  <p>Under Gradle (Kotlin DSL) it looks similar (although much shorter):</p>
  
  <pre><code>dependencies {
  
      ...
  
      // hibernate
      val hibernateVersion = "5.2.13.Final"
      implementation(group = "org.hibernate", name = "hibernate-core", version = hibernateVersion)
      implementation(group = "org.hibernate", name = "hibernate-entitymanager", version = hibernateVersion).
          exclude(group = "cglib", module = "cglib").
          exclude(group = "dom4j", module = "dom4j")
      implementation(group = "org.hibernate", name = "hibernate-validator", version = hibernateVersion)
      implementation(group = "org.hibernate", name = "hibernate-c3p0", version = hibernateVersion)
      implementation(group = "org.hibernate", name = "hibernate-java8", version = hibernateVersion)
  
      ...
  
  }
  </code></pre>
  
  <p>Persistence.xml is pretty standard:</p>
  
  <pre><code>&lt;persistence-unit name="default"&gt;
          &lt;description&gt;Persistence XML&lt;/description&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
  
              &lt;!-- Hibernate Config --&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect" /&gt;
              &lt;property name="hibernate.generate_statistics" value="false" /&gt;
  
              &lt;property name="hibernate.hbm2ddl.auto" value="validate"/&gt;
  
              &lt;property name="hibernate.physical_naming_strategy" value="com.application.util.CustomNamingStrategy"/&gt;
  
              &lt;property name="hibernate.connection.charSet" value="UTF-8"/&gt;
              &lt;property name="hibernate.show_sql" value="false" /&gt;
              &lt;property name="hibernate.format_sql" value="false"/&gt;
              &lt;property name="hibernate.use_sql_comments" value="false"/&gt;
  
              &lt;!-- JDBC Config --&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /&gt;
  
              &lt;property name="javax.persistence.jdbc.time_zone" value="UTC" /&gt;
              &lt;property name="hibernate.jdbc.time_zone" value="UTC"/&gt;
  
              &lt;!-- Connection Pool --&gt;
              &lt;property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" /&gt;
              &lt;property name="hibernate.c3p0.max_size" value="5" /&gt;
              &lt;property name="hibernate.c3p0.min_size" value="1" /&gt;
              &lt;property name="hibernate.c3p0.acquire_increment" value="1" /&gt;
              &lt;property name="hibernate.c3p0.idle_test_period" value="300" /&gt;
              &lt;property name="hibernate.c3p0.max_statements" value="0" /&gt;
              &lt;property name="hibernate.c3p0.timeout" value="100" /&gt;
  
              &lt;!-- Batch writing --&gt;
              &lt;property name="hibernate.jdbc.batch_size" value = "50"/&gt;
              &lt;!-- if this is switched on fixtures does not want to run for some or other reason --&gt;
              &lt;!--&lt;property name="hibernate.order_inserts" value = "true"/&gt;--&gt;
              &lt;property name="hibernate.order_updates" value = "true"/&gt;
              &lt;property name="hibernate.jdbc.batch_versioned_data" value = "true"/&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>Maven uses the standard shade plugin:</p>
  
  <pre><code>            &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4.3&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;shade&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;transformers&gt;
                                  &lt;transformer
                                          implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
                                      &lt;manifestEntries&gt;
                                          &lt;Main-Class&gt;ApplicationApi&lt;/Main-Class&gt;
                                      &lt;/manifestEntries&gt;
                                  &lt;/transformer&gt;
                              &lt;/transformers&gt;
                              &lt;filters&gt;
                                  &lt;filter&gt;
                                      &lt;artifact&gt;*:*&lt;/artifact&gt;
                                      &lt;excludes&gt;
                                          &lt;exclude&gt;META-INF/*.SF&lt;/exclude&gt;
                                          &lt;exclude&gt;META-INF/*.DSA&lt;/exclude&gt;
                                          &lt;exclude&gt;META-INF/*.RSA&lt;/exclude&gt;
                                          &lt;exclude&gt;junit:junit&lt;/exclude&gt;
                                          &lt;exclude&gt;rebel.xml&lt;/exclude&gt;
                                          &lt;exclude&gt;org.apache.maven:lib:tests&lt;/exclude&gt;
                                      &lt;/excludes&gt;
                                  &lt;/filter&gt;
                              &lt;/filters&gt;
                              &lt;artifactSet/&gt;
                              &lt;shadedArtifactAttached&gt;true&lt;/shadedArtifactAttached&gt;
                              &lt;shadedClassifierName&gt;standalone&lt;/shadedClassifierName&gt;
                              &lt;outputFile&gt;${project.build.directory}/api.jar&lt;/outputFile&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  </code></pre>
  
  <p>Whereas Gradle uses shadowJar plugin:</p>
  
  <pre><code>plugins {
      ...
      id("com.github.johnrengelman.shadow").version("5.0.0")
      ...
  }
  </code></pre>
  
  <p>Although running from IntelliJ doesn't use shade/shadow-jarring to run, so even if i remove shadow / shade jarring, it continues to exhibit the same behaviour. </p>
  
  <p>Something i did notice was the package structure after building, maven has everything under <code>classes</code> whereas Gradle splits classes into <code>java</code> / <code>kotlin</code></p>
  
  <p>Maven:</p>
  
  <p><a href="https://i.stack.imgur.com/6qf9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6qf9e.png" alt="enter image description here"></a></p>
  
  <p>Gradle:</p>
  
  <p><a href="https://i.stack.imgur.com/gpdOA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gpdOA.png" alt="enter image description here"></a></p>
  
  <p>I'm not sure if the above structure has any impact on annotation scanning.</p>
  
  <p>I've tried adding <code>&lt;property name="packagesToScan" value="....." /&gt;</code> in persistence.xml for each affected entity with no effect.</p>
  
  <p>Entities are all annotated correctly (as i mentioned, this still runs correctly under Maven)</p>
  
  <pre><code>@Entity
  @Table
  @PersistenceContext(unitName = "default")
  @Cacheable
  @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  @BatchSize(size = 50)
  class Account(
      email: String,
      ...
  </code></pre>
  
  <p>Any idea why i'm getting this error after switching to Gradle?</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: Account is not mapped [SELECT o FROM Account AS o WHERE lower(o.email)=:email]
      at org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConverterImpl.java:133)
      at org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConverterImpl.java:157)
      at org.hibernate.internal.ExceptionConverterImpl.convert (ExceptionConverterImpl.java:164)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery (AbstractSharedSessionContract.java:670)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery (AbstractSharedSessionContract.java:686)
      at org.hibernate.internal.AbstractSessionImpl.createQuery (AbstractSessionImpl.java:23)
  </code></pre>