diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index 465fa774c3b..602f18f80ed 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -30,45 +30,59 @@ apply plugin: 'se.thinkcode.cucumber-runner' check.dependsOn('cucumber') -// Split into separate tasks -task copyClasses(type: Copy) { - from sourceSets.main.java.classesDirectory - into layout.buildDirectory.dir("weaving/pre-weaving") -} +abstract class WeaveTask extends DefaultTask { + @InputDirectory + abstract DirectoryProperty getInputClasses() -task copyPersistenceXml(type: Copy) { - from "src/main/resources/jpa/persistence.xml" - into layout.buildDirectory.dir("weaving/pre-weaving/META-INF") - dependsOn copyClasses -} + @InputFile + abstract RegularFileProperty getPersistenceXml() -task weaveClasses { - inputs.dir layout.buildDirectory.dir("weaving/pre-weaving") - outputs.dir layout.buildDirectory.dir("weaving/weaved") + @OutputDirectory + abstract DirectoryProperty getOutputClasses() - doLast { - javaexec { - description = 'Performs EclipseLink static weaving of entity classes' - def sourceDir = layout.buildDirectory.dir("weaving/pre-weaving").get().asFile - def targetDir = layout.buildDirectory.dir("weaving/weaved").get().asFile - main 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave' - args '-persistenceinfo', sourceDir, sourceDir, targetDir - classpath sourceSets.main.runtimeClasspath + @TaskAction + void weave() { + def tempDir = new File(temporaryDir, "weaving-temp") + tempDir.mkdirs() + + project.copy { + from inputClasses + into tempDir + } + + project.copy { + from persistenceXml + into "${tempDir}/META-INF/" + } + + outputClasses.get().asFile.mkdirs() + + project.javaexec { + description = 'Performs EclipseLink static weaving' + main = 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave' + args '-persistenceinfo', tempDir, tempDir, outputClasses.get().asFile + classpath project.sourceSets.main.runtimeClasspath } } - dependsOn copyPersistenceXml } -// Update the classes directory after weaving -tasks.named('classes') { - dependsOn weaveClasses - doLast { - sourceSets.main.java.classesDirectory.set( - layout.buildDirectory.dir("weaving/weaved") - ) - } +def weaveTask = tasks.register('weaveClasses', WeaveTask) { + dependsOn 'generateGitProperties' + inputClasses.set(compileJava.destinationDirectory) + persistenceXml.set(layout.projectDirectory.file("src/main/resources/jpa/persistence.xml")) + outputClasses.set(layout.buildDirectory.dir("classes/weaved-main")) +} + +// Make weaving happen right after main compilation but before test compilation +tasks.named("compileJava") { + finalizedBy(weaveTask) } +// Point the main classes directory to weaved output +sourceSets.main.java.classesDirectory.set( + weaveTask.flatMap { it.outputClasses } +) + // Configuration for Swagger documentation generation task // https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-gradle-plugin import org.apache.tools.ant.filters.ReplaceTokens @@ -267,6 +281,10 @@ springBoot { mainClass = 'org.apache.fineract.ServerApplication' } +jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + bootJar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE manifest { @@ -384,7 +402,9 @@ checkstyleMain.dependsOn resolve checkstyleTest.dependsOn resolve rat.dependsOn prepareInputYaml spotbugsTest.dependsOn resolve -compileTestJava.dependsOn ':fineract-client:processResources', ':fineract-avro-schemas:processResources' +spotbugsMain.dependsOn weaveClasses +spotlessMisc.dependsOn weaveClasses +compileTestJava.dependsOn ':fineract-client:processResources', ':fineract-avro-schemas:processResources', ':fineract-provider:weaveClasses' resolveMainClassName.dependsOn resolve processResources.dependsOn compileJava