Skip to content

Commit 6cb60f4

Browse files
committed
FINERACT-2181: Some tweaks in the gradle build to ensure correct task processing
1 parent 25ef93a commit 6cb60f4

File tree

36 files changed

+522
-393
lines changed

36 files changed

+522
-393
lines changed

build.gradle

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ configure(project.fineractJavaProjects) {
365365
withJavadocJar()
366366
}
367367

368-
tasks.withType(ProcessResources) {
368+
tasks.withType(ProcessResources).configureEach {
369369
destinationDir = layout.buildDirectory.dir('classes/java/main').get().asFile
370370
}
371371

372372
// Add performance optimizations
373-
configurations.all {
373+
configurations.configureEach {
374374
resolutionStrategy {
375375
cacheChangingModulesFor 0, 'seconds'
376376
cacheDynamicVersionsFor 0, 'seconds'
@@ -422,40 +422,40 @@ configure(project.fineractJavaProjects) {
422422
configurations {
423423
api.setCanBeResolved(true)
424424
}
425-
tasks.withType(Copy) {
425+
tasks.withType(Copy).configureEach {
426426
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
427427
}
428-
tasks.withType(JavaCompile) {
428+
tasks.withType(JavaCompile).configureEach {
429429
options.compilerArgs += [
430-
"-Xlint:cast",
431-
"-Xlint:auxiliaryclass",
432-
"-Xlint:dep-ann",
433-
"-Xlint:divzero",
434-
"-Xlint:empty",
435-
"-Xlint:exports",
436-
"-Xlint:fallthrough",
437-
"-Xlint:finally",
438-
"-Xlint:module",
439-
"-Xlint:opens",
440-
"-Xlint:options",
441-
"-Xlint:overloads",
442-
"-Xlint:overrides",
443-
"-Xlint:path",
444-
"-Xlint:processing",
445-
"-Xlint:removal",
446-
"-Xlint:requires-automatic",
447-
"-Xlint:requires-transitive-automatic",
448-
"-Xlint:try",
449-
"-Xlint:varargs",
450-
"-Xlint:preview",
451-
"-Xlint:static",
452-
// -Werror needs to be disabled because EclipseLink's static weaving doesn't generate warning-free code
453-
// and during an IntelliJ recompilation, it fails
454-
//"-Werror",
455-
"-Xmaxwarns",
456-
"1500",
457-
"-Xmaxerrs",
458-
"1500"
430+
"-Xlint:cast",
431+
"-Xlint:auxiliaryclass",
432+
"-Xlint:dep-ann",
433+
"-Xlint:divzero",
434+
"-Xlint:empty",
435+
"-Xlint:exports",
436+
"-Xlint:fallthrough",
437+
"-Xlint:finally",
438+
"-Xlint:module",
439+
"-Xlint:opens",
440+
"-Xlint:options",
441+
"-Xlint:overloads",
442+
"-Xlint:overrides",
443+
"-Xlint:path",
444+
"-Xlint:processing",
445+
"-Xlint:removal",
446+
"-Xlint:requires-automatic",
447+
"-Xlint:requires-transitive-automatic",
448+
"-Xlint:try",
449+
"-Xlint:varargs",
450+
"-Xlint:preview",
451+
"-Xlint:static",
452+
// -Werror needs to be disabled because EclipseLink's static weaving doesn't generate warning-free code
453+
// and during an IntelliJ recompilation, it fails
454+
//"-Werror",
455+
"-Xmaxwarns",
456+
"1500",
457+
"-Xmaxerrs",
458+
"1500"
459459
]
460460
// TODO FINERACT-959 (gradually) enable -Xlint:all (see "javac -help -X")
461461

@@ -738,11 +738,13 @@ configure(project.fineractJavaProjects) {
738738
]
739739
}
740740

741-
tasks.withType(Javadoc) {
742-
options.addStringOption('Xdoclint:none', '-quiet')
743-
options.encoding = 'UTF-8'
744-
// Ignore any errors during javadoc generation
745-
failOnError = false
741+
tasks.withType(Javadoc).tap {
742+
configureEach {
743+
options.addStringOption('Xdoclint:none', '-quiet')
744+
options.encoding = 'UTF-8'
745+
// Ignore any errors during javadoc generation
746+
failOnError = false
747+
}
746748
}
747749
}
748750

@@ -868,17 +870,17 @@ configure(project.fineractPublishProjects) {
868870
}
869871
}
870872

871-
task printSourceSetInformation() {
872-
doLast{
873-
sourceSets.each { srcSet ->
874-
println "["+srcSet.name+"]"
875-
print "-->Source directories: "+srcSet.allJava.srcDirs+"\n"
876-
print "-->Output directories: "+srcSet.output.classesDirs.files+"\n"
877-
print "-->Compile classpath:\n"
878-
srcSet.compileClasspath.files.each {
879-
print " "+it.path+"\n"
873+
tasks.register('printSourceSetInformation') {
874+
doLast {
875+
sourceSets.each { srcSet ->
876+
println "[" + srcSet.name + "]"
877+
print "-->Source directories: " + srcSet.allJava.srcDirs + "\n"
878+
print "-->Output directories: " + srcSet.output.classesDirs.files + "\n"
879+
print "-->Compile classpath:\n"
880+
srcSet.compileClasspath.files.each {
881+
print " " + it.path + "\n"
882+
}
883+
println ""
880884
}
881-
println ""
882885
}
883886
}
884-
}

fineract-accounting/build.gradle

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,35 @@ 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+
tasks.register('staticWeaveJpa', JavaExec) {
25+
group = "build"
26+
description = "Performs EclipseLink static weaving of entity classes"
27+
28+
dependsOn classes
29+
30+
def classesDir = file("$buildDir/classes/java/main")
31+
32+
mainClass.set('org.eclipse.persistence.tools.weaving.jpa.StaticWeave')
33+
classpath = sourceSets.main.runtimeClasspath
34+
args '-persistenceinfo', classesDir.absolutePath, classesDir.absolutePath, classesDir.absolutePath
35+
}
36+
37+
staticWeaveJpa.doLast {
38+
delete "${sourceSets.main.output.classesDirs.asPath}/META-INF/persistence.xml"
39+
}
40+
41+
tasks.named('classes') {
42+
finalizedBy staticWeaveJpa
43+
}
44+
45+
tasks.named('processResources') {
46+
from('src/main/resources')
47+
into sourceSets.main.java.classesDirectory
48+
outputs.upToDateWhen { false }
49+
}
50+
51+
compileJava {
52+
dependsOn ':fineract-avro-schemas:buildJavaSdk'
4153
}
4254

4355
configurations {
@@ -85,10 +97,6 @@ eclipse {
8597
}
8698
}
8799

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-
92100
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
93101
sourceSets {
94102
test {

fineract-accounting/src/main/resources/jpa/accounting/persistence.xml renamed to fineract-accounting/src/main/resources/META-INF/persistence.xml

File renamed without changes.

fineract-accounting/src/main/resources/jpa/accounting/db/changelog/tenant/module/accounting/module-changelog-master.xml renamed to fineract-accounting/src/main/resources/db/changelog/tenant/module/accounting/module-changelog-master.xml

File renamed without changes.

fineract-avro-schemas/build.gradle

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ tasks.register('preprocessAvroSchemas', PreprocessAvroSchemasTask) {
5757
inputDir = file("$projectDir/src/main/avro")
5858
bigDecimalTemplate = file("$projectDir/src/main/resources/avro-templates/bigdecimal.avsc")
5959
outputDir = file("$buildDir/generated/avro/src/main/avro")
60+
finalizedBy buildJavaSdk
6061
}
6162

62-
task buildJavaSdk(type: GenerateAvroJavaTask) {
63+
tasks.register('buildJavaSdk', GenerateAvroJavaTask) {
64+
dependsOn preprocessAvroSchemas, spotlessJsonApply
6365
source("$buildDir/generated/avro/src/main/avro")
6466
outputDir = file("$buildDir/generated/java/src/main/java")
6567
templateDirectory = "$projectDir/src/main/resources/avro-generator-templates/"
@@ -73,12 +75,10 @@ spotless {
7375
}
7476
}
7577

76-
buildJavaSdk.dependsOn(preprocessAvroSchemas, spotlessJsonApply)
77-
7878
sourceSets {
7979
main {
8080
java {
81-
srcDir file("$buildDir/generated/java/src/main/java")
81+
srcDirs += "$buildDir/generated/java/src/main/java"
8282
}
8383
resources {
8484
srcDir file("$projectDir/src/main/resources")
@@ -97,7 +97,7 @@ jar {
9797
}
9898

9999
compileJava {
100-
dependsOn buildJavaSdk
100+
dependsOn buildJavaSdk, processResources
101101
source = sourceSets.main.java.srcDirs
102102
options.compilerArgs += ['-parameters']
103103
}
@@ -131,3 +131,9 @@ tasks.named('sourcesJar') {
131131
dependsOn tasks.named('buildJavaSdk')
132132
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
133133
}
134+
135+
tasks.named('processResources') {
136+
from('src/main/resources')
137+
into sourceSets.main.java.classesDirectory
138+
outputs.upToDateWhen { false }
139+
}

fineract-branch/build.gradle

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,35 @@ 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+
tasks.register('staticWeaveJpa', JavaExec) {
25+
group = "build"
26+
description = "Performs EclipseLink static weaving of entity classes"
27+
28+
dependsOn classes
29+
30+
def classesDir = file("$buildDir/classes/java/main")
31+
32+
mainClass.set('org.eclipse.persistence.tools.weaving.jpa.StaticWeave')
33+
classpath = sourceSets.main.runtimeClasspath
34+
args '-persistenceinfo', classesDir.absolutePath, classesDir.absolutePath, classesDir.absolutePath
35+
}
36+
37+
staticWeaveJpa.doLast {
38+
delete "${sourceSets.main.output.classesDirs.asPath}/META-INF/persistence.xml"
39+
}
40+
41+
tasks.named('classes') {
42+
finalizedBy staticWeaveJpa
43+
}
44+
45+
tasks.named('processResources') {
46+
from('src/main/resources')
47+
into sourceSets.main.java.classesDirectory
48+
outputs.upToDateWhen { false }
49+
}
50+
51+
compileJava {
52+
dependsOn ':fineract-avro-schemas:buildJavaSdk'
4153
}
4254

4355
// Configuration for Swagger documentation generation task
@@ -91,10 +103,6 @@ eclipse {
91103
}
92104
}
93105

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-
98106
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
99107
sourceSets {
100108
test {

fineract-branch/src/main/resources/jpa/branch/persistence.xml renamed to fineract-branch/src/main/resources/META-INF/persistence.xml

File renamed without changes.

fineract-charge/build.gradle

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,35 @@ description = 'Fineract Charge'
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/charge/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+
tasks.register('staticWeaveJpa', JavaExec) {
25+
group = "build"
26+
description = "Performs EclipseLink static weaving of entity classes"
27+
28+
dependsOn classes
29+
30+
def classesDir = file("$buildDir/classes/java/main")
31+
32+
mainClass.set('org.eclipse.persistence.tools.weaving.jpa.StaticWeave')
33+
classpath = sourceSets.main.runtimeClasspath
34+
args '-persistenceinfo', classesDir.absolutePath, classesDir.absolutePath, classesDir.absolutePath
35+
}
36+
37+
staticWeaveJpa.doLast {
38+
delete "${sourceSets.main.output.classesDirs.asPath}/META-INF/persistence.xml"
39+
}
40+
41+
tasks.named('classes') {
42+
finalizedBy staticWeaveJpa
43+
}
44+
45+
tasks.named('processResources') {
46+
from('src/main/resources')
47+
into sourceSets.main.java.classesDirectory
48+
outputs.upToDateWhen { false }
49+
}
50+
51+
compileJava {
52+
dependsOn ':fineract-avro-schemas:buildJavaSdk'
4153
}
4254

4355
// Configuration for Swagger documentation generation task
@@ -91,10 +103,6 @@ eclipse {
91103
}
92104
}
93105

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-
98106
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
99107
sourceSets {
100108
test {

fineract-charge/src/main/resources/jpa/charge/persistence.xml renamed to fineract-charge/src/main/resources/META-INF/persistence.xml

File renamed without changes.

fineract-charge/src/main/resources/jpa/charge/db/changelog/tenant/module/charge/module-changelog-master.xml renamed to fineract-charge/src/main/resources/db/changelog/tenant/module/charge/module-changelog-master.xml

File renamed without changes.

0 commit comments

Comments
 (0)