Last active
April 25, 2024 16:30
-
-
Save hectorlf/8973260 to your computer and use it in GitHub Desktop.
EclipseLink static weaving Gradle task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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