Skip to content

Instantly share code, notes, and snippets.

@hectorlf
Last active August 29, 2015 14:16
Show Gist options
  • Save hectorlf/e40377e12eaf3d7b2e7a to your computer and use it in GitHub Desktop.
Save hectorlf/e40377e12eaf3d7b2e7a to your computer and use it in GitHub Desktop.
OpenJPA static weaving Gradle task
apply plugin: 'java'
def entitiesBasePackage = 'your.package.here'
configurations {
weave
}
dependencies {
weave 'org.apache.openjpa:openjpa:2.3.0'
weave 'org.slf4j:jcl-over-slf4j:1.7.10'
weave 'ch.qos.logback:logback-classic:1.1.2'
}
compileJava {
destinationDir file("$buildDir/compiled-classes")
}
// jpa weaving
task copyNonPersistentClasses(type: Copy, dependsOn: compileJava) {
from("$buildDir/compiled-classes")
into sourceSets.main.output.classesDir
exclude '**/' + entitiesBasePackage.replaceAll('\\.','/') + '/**'
includeEmptyDirs = false
}
task copyPersistentClasses(type: Copy, dependsOn: compileJava) {
from("$buildDir/compiled-classes")
into "$buildDir/unwoven-persistent-classes"
include '**/' + entitiesBasePackage.replaceAll('\\.','/') + '/**'
includeEmptyDirs = false
}
task weaveJpaEntities(type: JavaExec, dependsOn: [copyPersistentClasses,processResources]) {
main = 'org.apache.openjpa.enhance.PCEnhancer'
classpath configurations.weave.incoming.files
doFirst {
classpath copyPersistentClasses.destinationDir
args '-tcl'
args 'false'
args '-d'
args sourceSets.main.output.classesDir.absolutePath
args '-p'
args fileTree(processResources.destinationDir).matching({pattern -> pattern.include('**/META-INF/persistence.xml')}).singleFile.absolutePath
}
inputs.files fileTree(copyPersistentClasses.destinationDir),fileTree(processResources.destinationDir).matching({pattern -> pattern.include('**/META-INF/persistence.xml')})
outputs.dir sourceSets.main.output.classesDir
}
classes.dependsOn copyNonPersistentClasses,weaveJpaEntities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment