Skip to content

Instantly share code, notes, and snippets.

@hectorlf
Last active April 25, 2024 16:30
Show Gist options
  • Save hectorlf/8973260 to your computer and use it in GitHub Desktop.
Save hectorlf/8973260 to your computer and use it in GitHub Desktop.
EclipseLink static weaving Gradle task
apply plugin: 'java'
def entitiesBasePackage = 'your.package.here'
configurations {
weave
}
dependencies {
weave 'org.eclipse.persistence:javax.persistence:2.1.0'
weave 'org.eclipse.persistence:org.eclipse.persistence.jpa:2.5.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.eclipse.persistence.tools.weaving.jpa.StaticWeave'
classpath configurations.weave.incoming.files
args '-persistenceinfo'
args processResources.destinationDir.absolutePath
args '-classpath'
args configurations.compile.incoming.files.asPath
args '-loglevel'
args 'INFO'
args copyPersistentClasses.destinationDir.absolutePath
args sourceSets.main.output.classesDir.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