Skip to content

Commit

Permalink
weave with cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozsa committed Jan 8, 2025
1 parent 2a499c0 commit 2d29cee
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions fineract-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -267,6 +281,10 @@ springBoot {
mainClass = 'org.apache.fineract.ServerApplication'
}

jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

bootJar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2d29cee

Please sign in to comment.