ネットに転がっている方法を寄せ集めただけですが。
いくつかのpersstence.xmlを使っている場合にも対応しています。
元のクラスも(何に使うのかはわからんが)残しています。
openjpa.gradle
def relativize = {file->
projectDir.toURI().relativize(file.toURI()).toString()
}
task(enhance,dependsOn:classes) << {
description 'OpenJPA enhancer task.'
ant.taskdef (
name : 'openjpac',
classpath : project.runtimeClasspath.asPath,
classname : 'org.apache.openjpa.ant.PCEnhancerTask'
)
def resurcesDir = sourceSets.main.output.resourcesDir
def mainOutDir = relativize(sourceSets.main.output.classesDir)
def jpacOutDir = relativize(sourceSets.main.output.classesDir) - ~/\/$/+ '_jpa/'
def orgDir = relativize(sourceSets.main.output.classesDir) - ~/\/$/+ '_org/'
ant.mkdir(dir:orgDir)
ant.copy(todir:orgDir){
fileset(dir:mainOutDir){
include(name:'**')
}
}
resurcesDir.eachFileRecurse(groovy.io.FileType.FILES) {
propertiesFile ->
ant.mkdir(dir:jpacOutDir)
if(propertiesFile.name ==~ /.*persistence.*\.xml/){
def propertiesFilePath = relativize(propertiesFile)
ant.openjpac(
classpath:project.runtimeClasspath.asPath,
addDefaultConstructor:true,
enforcePropertyRestrictions:true,
directory:jpacOutDir
){
config(propertiesFile:propertiesFilePath)
}
}
ant.move(todir:mainOutDir){
fileset(dir:jpacOutDir){
include(name:'**')
}
}
ant.delete(dir:jpacOutDir)
}
}
jar {
dependsOn enhance
}