eclipselink metamodel with gradle and groovy

1.4k Views Asked by At

How i can get generate metamodel classes from org.eclipse.persistence.jpa.modelgen.processor in gradle?

In maven i use someone like

<plugin> <artifactId>maven-compiler-plugin</artifactId> <dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> <version>${eclipselink.version}</version> </dependency> </dependencies> <configuration> <compilerArgs> <compilerArg>-Aeclipselink.persistenceunits=unit-name </compilerArg> </compilerArgs> </configuration> </plugin>

Thanks for any advice.

2

There are 2 best solutions below

0
On

Probably too late for you to be useful, but wanted to share how I solved the problem. The following will generate metamodel every time you compile. Note, if you remove the line with delete, the compiler will probably complain.

ext {
    metamodelPath="$buildDir/generated-sources/metamodel"
}
compileJava {

    doFirst {
        file(metamodelPath).delete()
        file(metamodelPath).mkdirs()
    }
    options.compilerArgs += ['-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml', '-s', metamodelPath ]
}
0
On

Unfortunately the previous solution does not work for me. But it was a good starting point. The dependencies closure is missing.

This works under Gradle 5.6.1 and Groovy 2.5.4:

ext {
    eclipselink='2.7.3'
    metamodelPath="$buildDir/generated/sources/metamodel/java/main"
    persistenceXMLLocation="src/main/resources/META-INF/persistence.xml"
}

compileJava {
    doFirst {
        file(metamodelPath).delete()
        file(metamodelPath).mkdirs()
    }
    options.compilerArgs += ["-Aeclipselink.persistencexml=${new File(project.projectDir, persistenceXMLLocation).absolutePath}", '-s', metamodelPath]
}

dependencies {
    api "org.eclipse.persistence:eclipselink:$eclipselink"
    annotationProcessor "org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:$eclipselink"
}