alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (hibernate-entitymanager.gradle)

This example Hibernate source code file (hibernate-entitymanager.gradle) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

compile, compile, copy, copy

The Hibernate hibernate-entitymanager.gradle source code

import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'java'
apply plugin: org.hibernate.gradle.testing.matrix.MatrixTestingPlugin

dependencies {
    shrinkwrapVersion = '1.0.0-beta-5'

    compile( project(':hibernate-core') )
    compile( libraries.dom4j )
    compile( libraries.commons_annotations )
    compile( libraries.jpa )
    compile( libraries.jta )
    compile( libraries.javassist )
    testCompile( project(':hibernate-testing') )
    testCompile( libraries.junit )
    testCompile( libraries.shrinkwrap_api )
    testCompile( libraries.shrinkwrap )
    testCompile( libraries.validation )
    testRuntime( libraries.validator )
}

aptDumpDir = file( buildDirName + "/tmp/apt" )

sourceSets.test {
    originalJavaSrcDirs = java.srcDirs
    generatedJpaMetamodelSrcDir = file( "${buildDir}/generated-src/jpamodelgen/${name}" )
    java.srcDir generatedJpaMetamodelSrcDir
}
sourceSets {
    matrix {
        java {
            srcDir 'src/matrix/java'
        }
        resources {
            srcDir 'src/matrix/resources'
        }
    }
}
ideaModule {
    excludeDirs += file("$buildDir/bundles")
    testSourceDirs += file( 'src/matrix/java')
    testSourceDirs += file( 'src/matrix/resources')
}

task generateJpaMetamodelClasses(type: Compile) {
    classpath = compileTestJava.classpath + configurations.hibernateJpaModelGenTool
    source = sourceSets.test.originalJavaSrcDirs
    destinationDir = aptDumpDir
    options.define(
            compilerArgs: [
                    "-proc:only",
                    "-processor", "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor",
                    "-s", "$sourceSets.test.generatedJpaMetamodelSrcDir.absolutePath"
            ]
    );
    outputs.dir sourceSets.test.generatedJpaMetamodelSrcDir;
    doFirst {
        sourceSets.test.generatedJpaMetamodelSrcDir.mkdirs()
    }
}

// for the time being eat the annoying output from running the annotation processors
generateJpaMetamodelClasses.logging.captureStandardError(LogLevel.INFO)

compileTestJava.dependsOn generateJpaMetamodelClasses
compileTestJava.options.define(compilerArgs: ["-proc:none"])


bundlesTargetDir = file( "$buildDirName/bundles" )
task copyBundleResources (type: Copy) {
    from file('src/test/bundles') 
    into bundlesTargetDir
    filter(ReplaceTokens, tokens: [
            buildDirName: buildDir.absolutePath,
            'db.dialect': 'org.hibernate.dialect.H2Dialect',
            'jdbc.driver': 'org.h2.Driver',
            'jdbc.user': 'sa',
            'jdbc.pass': '',
            'jdbc.url': 'jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE',
    ]);
    doFirst {
        bundlesTargetDir.mkdirs()
    }
}

// make sure that the bundles for the packaged test (PackagingTestCase) are copied as well
processTestResources.dependsOn copyBundleResources

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate hibernate-entitymanager.gradle source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.