Skip to content

Commit db28259

Browse files
committed
FINERACT-2181: Gradle task rework - Optimized weaving across all modules
1 parent ee5290c commit db28259

File tree

36 files changed

+1267
-900
lines changed

36 files changed

+1267
-900
lines changed

STATIC_WEAVING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Static Weaving Configuration
2+
3+
This document explains the static weaving setup for JPA entities in the Fineract project.
4+
5+
## Overview
6+
7+
Static weaving is a process that enhances JPA entities at build time to improve runtime performance. This is done using the `org.eclipse.persistence.tools.weaving.jpa.StaticWeave` which processes the compiled classes and applies the necessary bytecode transformations.
8+
9+
## Configuration
10+
11+
The static weaving is configured in `static-weaving.gradle` and applied to all Java projects that contain JPA entities.
12+
13+
## How It Works
14+
15+
1. **Compilation**: Java source files are compiled to the standard classes directory (`build/classes/java/main`).
16+
2. **Weaving**: Weaving happens as last step of **compileJava** task, which outputs them to the standard classes directory (`build/classes/java/main`).
17+
18+
## Adding Static Weaving to a Module
19+
20+
1. Add JPA entities to `src/main/java`
21+
2. Ensure there's a `persistence.xml` file in `src/main/resources/jpa/static-weaving/module/[module-name]/`
22+
3. The build will automatically detect and apply static weaving
23+
24+
## Troubleshooting
25+
26+
If you encounter issues with static weaving:
27+
28+
1. Check that the `persistence.xml` file exists in the correct location
29+
2. Verify that the output directories are being created correctly
30+
3. Check the build logs for any weaving-related errors

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ gitVersioning.apply {
146146
ext['groovy.version'] = '4.0.17'
147147
ext['swaggerFile'] = "$rootDir/fineract-provider/build/classes/java/main/static/fineract.json".toString()
148148

149+
// Apply static weaving configuration to all subprojects
150+
subprojects { subproject ->
151+
apply from: rootProject.file('static-weaving.gradle')
152+
}
153+
149154
allprojects {
150155
group = 'org.apache.fineract'
151156

@@ -406,10 +411,6 @@ configure(project.fineractJavaProjects) {
406411

407412
group = 'org.apache.fineract'
408413

409-
/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */
410-
sourceSets.main.output.resourcesDir = sourceSets.main.java.classesDirectory
411-
sourceSets.test.output.resourcesDir = sourceSets.test.java.classesDirectory
412-
413414
configurations.named('spotbugs').configure {
414415
resolutionStrategy.eachDependency {
415416
if (it.requested.group == 'org.ow2.asm') {

fineract-accounting/build.gradle

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,8 @@ description = 'Fineract Accounting'
2121
apply plugin: 'java'
2222
apply plugin: 'eclipse'
2323

24-
compileJava.doLast {
25-
def mainSS = sourceSets.main
26-
def source = mainSS.java.classesDirectory.get()
27-
copy {
28-
from file("src/main/resources/jpa/accounting/persistence.xml")
29-
into "${source}/META-INF/"
30-
}
31-
javaexec {
32-
description = 'Performs EclipseLink static weaving of entity classes'
33-
def target = source
34-
mainClass = 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave'
35-
args '-persistenceinfo', source, source, target
36-
classpath sourceSets.main.runtimeClasspath
37-
}
38-
delete {
39-
delete "${source}/META-INF/persistence.xml"
40-
}
24+
compileJava {
25+
dependsOn ':fineract-avro-schemas:buildJavaSdk'
4126
}
4227

4328
configurations {
@@ -85,10 +70,6 @@ eclipse {
8570
}
8671
}
8772

88-
/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */
89-
sourceSets.main.output.resourcesDir = sourceSets.main.java.classesDirectory
90-
sourceSets.test.output.resourcesDir = sourceSets.test.java.classesDirectory
91-
9273
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
9374
sourceSets {
9475
test {

fineract-accounting/src/main/resources/jpa/accounting/persistence.xml

Lines changed: 0 additions & 51 deletions
This file was deleted.

fineract-loan/src/main/resources/jpa/loan/persistence.xml renamed to fineract-accounting/src/main/resources/jpa/static-weaving/module/fineract-accounting/persistence.xml

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,69 @@
2222

2323

2424
<persistence version="2.0"
25-
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26-
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
25+
xmlns="http://java.sun.com/xml/ns/persistence"
26+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
2728

2829
<!-- This file is only used for static weaving, nothing more. -->
2930
<!-- You can find the runtime configuration in the JPAConfig class -->
3031
<persistence-unit name="jpa-pu" transaction-type="RESOURCE_LOCAL">
3132
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
32-
<!-- Fineract core module -->
33-
<class>org.apache.fineract.accounting.glaccount.domain.GLAccount</class>
34-
<class>org.apache.fineract.accounting.journalentry.domain.JournalEntry</class>
35-
<class>org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom</class>
36-
<class>org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom</class>
37-
<class>org.apache.fineract.infrastructure.codes.domain.Code</class>
38-
<class>org.apache.fineract.infrastructure.codes.domain.CodeValue</class>
33+
34+
<!-- Core Module Entities -->
35+
<class>org.apache.fineract.useradministration.domain.Role</class>
36+
<class>org.apache.fineract.portfolio.fund.domain.Fund</class>
3937
<class>org.apache.fineract.infrastructure.documentmanagement.domain.Image</class>
40-
<class>org.apache.fineract.organisation.staff.domain.Staff</class>
41-
<class>org.apache.fineract.organisation.office.domain.Office</class>
38+
<class>org.apache.fineract.organisation.workingdays.domain.WorkingDays</class>
39+
<class>org.apache.fineract.useradministration.domain.Permission</class>
40+
<class>org.apache.fineract.useradministration.domain.AppUserClientMapping</class>
41+
<class>org.apache.fineract.commands.domain.CommandSource</class>
42+
<class>org.apache.fineract.useradministration.domain.AppUser</class>
43+
<class>org.apache.fineract.accounting.glaccount.domain.GLAccount</class>
4244
<class>org.apache.fineract.organisation.monetary.domain.OrganisationCurrency</class>
45+
<class>org.apache.fineract.organisation.staff.domain.Staff</class>
46+
<class>org.apache.fineract.portfolio.rate.domain.Rate</class>
4347
<class>org.apache.fineract.organisation.monetary.domain.ApplicationCurrency</class>
44-
<class>org.apache.fineract.organisation.holiday.domain.Holiday</class>
45-
<class>org.apache.fineract.organisation.workingdays.domain.WorkingDays</class>
46-
<class>org.apache.fineract.portfolio.group.domain.Group</class>
47-
<class>org.apache.fineract.portfolio.group.domain.GroupLevel</class>
48-
<class>org.apache.fineract.portfolio.group.domain.StaffAssignmentHistory</class>
49-
<class>org.apache.fineract.portfolio.group.domain.GroupRole</class>
50-
<class>org.apache.fineract.portfolio.client.domain.Client</class>
48+
<class>org.apache.fineract.portfolio.calendar.domain.CalendarInstance</class>
49+
<class>org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail</class>
50+
<class>org.apache.fineract.portfolio.calendar.domain.Calendar</class>
51+
<class>org.apache.fineract.portfolio.calendar.domain.CalendarHistory</class>
5152
<class>org.apache.fineract.portfolio.client.domain.ClientIdentifier</class>
52-
<class>org.apache.fineract.portfolio.rate.domain.Rate</class>
53-
<class>org.apache.fineract.portfolio.fund.domain.Fund</class>
5453
<class>org.apache.fineract.portfolio.delinquency.domain.DelinquencyBucket</class>
5554
<class>org.apache.fineract.portfolio.delinquency.domain.DelinquencyRange</class>
55+
<class>org.apache.fineract.portfolio.group.domain.StaffAssignmentHistory</class>
56+
<class>org.apache.fineract.portfolio.group.domain.Group</class>
57+
<class>org.apache.fineract.portfolio.client.domain.Client</class>
58+
<class>org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration</class>
59+
<class>org.apache.fineract.portfolio.group.domain.GroupRole</class>
5660
<class>org.apache.fineract.portfolio.paymenttype.domain.PaymentType</class>
57-
<class>org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail</class>
58-
<class>org.apache.fineract.portfolio.floatingrates.domain.FloatingRate</class>
59-
<class>org.apache.fineract.portfolio.floatingrates.domain.FloatingRatePeriod</class>
60-
<class>org.apache.fineract.portfolio.calendar.domain.Calendar</class>
61-
<class>org.apache.fineract.portfolio.calendar.domain.CalendarHistory</class>
62-
<class>org.apache.fineract.portfolio.calendar.domain.CalendarInstance</class>
63-
<class>org.apache.fineract.useradministration.domain.AppUser</class>
64-
<class>org.apache.fineract.useradministration.domain.Role</class>
65-
<class>org.apache.fineract.useradministration.domain.Permission</class>
66-
<class>org.apache.fineract.useradministration.domain.AppUserClientMapping</class>
67-
<!-- Fineract Charge module -->
61+
<class>org.apache.fineract.portfolio.group.domain.GroupLevel</class>
62+
<class>org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEvent</class>
63+
<class>org.apache.fineract.organisation.office.domain.Office</class>
64+
<class>org.apache.fineract.organisation.holiday.domain.Holiday</class>
65+
<class>org.apache.fineract.infrastructure.cache.domain.PlatformCache</class>
66+
<class>org.apache.fineract.infrastructure.codes.domain.Code</class>
67+
<class>org.apache.fineract.infrastructure.businessdate.domain.BusinessDate</class>
68+
<class>org.apache.fineract.infrastructure.codes.domain.CodeValue</class>
69+
70+
<!-- Accounting Module Entities -->
71+
<class>org.apache.fineract.accounting.closure.domain.GLClosure</class>
72+
<class>org.apache.fineract.accounting.financialactivityaccount.domain.FinancialActivityAccount</class>
73+
<class>org.apache.fineract.accounting.glaccount.domain.TrialBalance</class>
74+
<class>org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping</class>
75+
<class>org.apache.fineract.accounting.rule.domain.AccountingRule</class>
76+
<class>org.apache.fineract.accounting.rule.domain.AccountingTagRule</class>
77+
<class>org.apache.fineract.accounting.journalentry.domain.JournalEntry</class>
78+
79+
<!-- Charge Module Entities -->
6880
<class>org.apache.fineract.portfolio.charge.domain.Charge</class>
69-
<!-- Fineract Tax module -->
70-
<class>org.apache.fineract.portfolio.tax.domain.TaxGroup</class>
71-
<class>org.apache.fineract.portfolio.tax.domain.TaxGroupMappings</class>
81+
82+
<!-- Tax Module Entities -->
7283
<class>org.apache.fineract.portfolio.tax.domain.TaxComponent</class>
7384
<class>org.apache.fineract.portfolio.tax.domain.TaxComponentHistory</class>
74-
<class>org.apache.fineract.portfolio.loanaccount.domain.LoanStatusConverter</class>
85+
<class>org.apache.fineract.portfolio.tax.domain.TaxGroup</class>
86+
<class>org.apache.fineract.portfolio.tax.domain.TaxGroupMappings</class>
87+
7588
<exclude-unlisted-classes>false</exclude-unlisted-classes>
7689
<properties>
7790
<property name="eclipselink.weaving" value="static" />

fineract-branch/build.gradle

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,10 @@ description = 'Fineract Branch'
2121
apply plugin: 'java'
2222
apply plugin: 'eclipse'
2323

24-
compileJava.doLast {
25-
def mainSS = sourceSets.main
26-
def source = mainSS.java.classesDirectory.get()
27-
copy {
28-
from file("src/main/resources/jpa/branch/persistence.xml")
29-
into "${source}/META-INF/"
30-
}
31-
javaexec {
32-
description = 'Performs EclipseLink static weaving of entity classes'
33-
def target = source
34-
main 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave'
35-
args '-persistenceinfo', source, source, target
36-
classpath sourceSets.main.runtimeClasspath
37-
}
38-
delete {
39-
delete "${source}/META-INF/persistence.xml"
40-
}
24+
compileJava {
25+
dependsOn ':fineract-avro-schemas:buildJavaSdk'
4126
}
4227

43-
// Configuration for Swagger documentation generation task
44-
// https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-gradle-plugin
45-
import org.apache.tools.ant.filters.ReplaceTokens
46-
47-
48-
4928
configurations {
5029
providedRuntime // needed for Spring Boot executable WAR
5130
providedCompile
@@ -91,10 +70,6 @@ eclipse {
9170
}
9271
}
9372

94-
/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */
95-
sourceSets.main.output.resourcesDir = sourceSets.main.java.classesDirectory
96-
sourceSets.test.output.resourcesDir = sourceSets.test.java.classesDirectory
97-
9873
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
9974
sourceSets {
10075
test {

0 commit comments

Comments
 (0)