From 88ba8462461fd7d431d470466486feafb3523a14 Mon Sep 17 00:00:00 2001 From: Kristof Jozsa Date: Sun, 15 Sep 2024 21:55:21 +0200 Subject: [PATCH] wip --- build.gradle | 12 +- fineract-provider/build.gradle | 208 +++++++++++++-------------------- gradle.properties | 4 +- 3 files changed, 90 insertions(+), 134 deletions(-) diff --git a/build.gradle b/build.gradle index 5b8f8b39490..5cbeed70171 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ - /** +/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -106,7 +106,7 @@ plugins { // id 'org.asciidoctor.jvm.gems' version '3.3.2' apply false id 'org.asciidoctor.kindlegen.base' version '3.2.0' apply false id 'com.google.cloud.tools.jib' version '3.4.3' apply false - id 'org.sonarqube' version '4.4.1.3373' + id 'org.sonarqube' version '4.4.1.3373' apply false id 'com.github.andygoossens.modernizer' version '1.9.3' apply false // TODO: upgrade to 6.0.4 id 'com.github.spotbugs' version '6.0.22' apply false @@ -325,7 +325,6 @@ configure(project.fineractJavaProjects) { apply plugin: 'java' apply plugin: 'idea' - apply plugin: 'eclipse' apply plugin: 'checkstyle' apply plugin: 'jacoco' apply plugin: 'net.ltgt.errorprone' @@ -806,3 +805,10 @@ task printSourceSetInformation() { } } } + +if ('sonarqube' in gradle.startParameter.taskNames) { + apply plugin: 'org.sonarqube' + tasks.named('sonarqube') { + dependsOn build + } +} diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index 8f4f2121eb2..846cb8d8b73 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -25,64 +25,53 @@ apply plugin: 'org.springframework.boot' apply plugin: 'com.gorylenko.gradle-git-properties' apply plugin: 'io.swagger.core.v3.swagger-gradle-plugin' apply plugin: 'com.google.cloud.tools.jib' -apply plugin: 'org.springframework.boot' apply plugin: 'se.thinkcode.cucumber-runner' check.dependsOn('cucumber') compileJava.doLast { - def mainSS = sourceSets.main - def source = mainSS.java.classesDirectory.get() + def source = sourceSets.main.java.classesDirectory.get() copy { - from file("src/main/resources/jpa/persistence.xml") + from file('src/main/resources/jpa/persistence.xml') into "${source}/META-INF/" } javaexec { description = 'Performs EclipseLink static weaving of entity classes' - def target = source - main 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave' - args '-persistenceinfo', source, source, target + main = 'org.eclipse.persistence.tools.weaving.jpa.StaticWeave' + args '-persistenceinfo', source, source, source classpath sourceSets.main.runtimeClasspath } - delete { - delete "${source}/META-INF/persistence.xml" - } + delete "${source}/META-INF/persistence.xml" } -// 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 - task prepareInputYaml { - outputs.file("${buildDir}/tmp/swagger/fineract-input.yaml") - + inputs.file('config/swagger/fineract-input.yaml.template') + outputs.file("$buildDir/tmp/swagger/fineract-input.yaml") doLast { copy { - from file("${projectDir}/config/swagger/fineract-input.yaml.template") - into file("${buildDir}/tmp/swagger") - rename { String filename -> return 'fineract-input.yaml' } - filter(ReplaceTokens, tokens: [VERSION: "${project.version}".toString()]) + from file('config/swagger/fineract-input.yaml.template') + into file("$buildDir/tmp/swagger") + rename { String filename -> 'fineract-input.yaml' } + filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [VERSION: project.version.toString()]) } } } resolve { - logging.captureStandardOutput LogLevel.INFO outputFileName = 'fineract' outputFormat = 'JSONANDYAML' - prettyPrint = false classpath = sourceSets.main.runtimeClasspath - buildClasspath = classpath - outputDir = file("${buildDir}/classes/java/main/static") - openApiFile = file("${buildDir}/tmp/swagger/fineract-input.yaml") + outputDir = file("$buildDir/classes/java/main/static") + openApiFile = file("$buildDir/tmp/swagger/fineract-input.yaml") sortOutput = true - dependsOn(prepareInputYaml) + dependsOn prepareInputYaml } configurations { - providedRuntime // needed for Spring Boot executable WAR + providedRuntime providedCompile - compile() { + driver + compile { exclude module: 'hibernate-entitymanager' exclude module: 'hibernate-validator' exclude module: 'activation' @@ -97,13 +86,23 @@ configurations { exclude module: 'itext-rtf' exclude module: 'classworlds' } - runtime } apply from: 'dependencies.gradle' -// Configuration for the modernizer plugin -// https://github.com/andygoossens/gradle-modernizer-plugin +dependencies { + implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.postgresql:postgresql' + implementation 'org.mariadb.jdbc:mariadb-java-client' + implementation 'mysql:mysql-connector-java:8.0.33' + // Add other dependencies as needed + + // Driver dependencies for SQL tasks + driver 'org.postgresql:postgresql' + driver 'org.mariadb.jdbc:mariadb-java-client' + driver 'mysql:mysql-connector-java:8.0.33' +} + modernizer { ignoreClassNamePatterns = [ '.*AbstractPersistableCustom', @@ -112,25 +111,17 @@ modernizer { ] } -// If we are running Gradle within Eclipse to enhance classes with OpenJPA, -// set the classes directory to point to Eclipse's default build directory -if (project.hasProperty('env') && project.getProperty('env') == 'eclipse') { - sourceSets.main.java.outputDir = new File(rootProject.projectDir, "fineract-provider/bin/main") +if (project.hasProperty('env') && project.env == 'eclipse') { + sourceSets.main.java.outputDir = file('bin/main') } -eclipse { - project { - buildCommand([ LaunchConfigHandle: "/.externalToolBuilders/OpenJPA Enhance Builder.launch" ], 'org.eclipse.ui.externaltools.ExternalToolBuilder') +sourceSets { + main { + output.resourcesDir = java.classesDirectory } -} - -/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */ -sourceSets.main.output.resourcesDir = sourceSets.main.java.classesDirectory -sourceSets.test.output.resourcesDir = sourceSets.test.java.classesDirectory - -if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) { - sourceSets { - test { + test { + output.resourcesDir = java.classesDirectory + if (!(project.hasProperty('env') && project.env == 'dev')) { java { exclude '**/core/boot/tests/**' } @@ -138,82 +129,60 @@ if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) { } } -// Configuration for SQL tasks -// https://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html import groovy.sql.Sql -project.ext.mysqlUser='root' -project.ext.mysqlPassword='mysql' -project.ext.pgUser='root' -project.ext.pgPassword='postgres' - -configurations { - driver -} -dependencies { - driver 'org.mariadb.jdbc:mariadb-java-client' - driver 'org.postgresql:postgresql' - driver 'mysql:mysql-connector-java:8.0.33' -} - -URLClassLoader loader = GroovyObject.class.classLoader -configurations.driver.each {File file -> - loader.addURL(file.toURL()) +ext { + mysqlUser = 'root' + mysqlPassword = 'mysql' + pgUser = 'root' + pgPassword = 'postgres' } task createDB { - description= "Creates the MariaDB Database. Needs database name to be passed (like: -PdbName=someDBname)" + description = 'Creates the MariaDB Database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver' ) - sql.execute( 'CREATE DATABASE '+"`$dbName` CHARACTER SET utf8mb4" ) + def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver') + sql.execute("CREATE DATABASE `${dbName}` CHARACTER SET utf8mb4") } } task dropDB { - description= "Drops the specified MariaDB database. The database name has to be passed (like: -PdbName=someDBname)" + description = 'Drops the specified MariaDB database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver' ) - sql.execute( 'DROP DATABASE '+"`$dbName`") + def sql = Sql.newInstance('jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver') + sql.execute("DROP DATABASE `${dbName}`") } } task createPGDB { - description= "Creates the PostgreSQL Database. Needs database name to be passed (like: -PdbName=someDBname)" + description = 'Creates the PostgreSQL Database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:postgresql://localhost:5432/', pgUser, pgPassword, 'org.postgresql.Driver' ) - sql.execute( 'create database '+"$dbName" ) + def sql = Sql.newInstance('jdbc:postgresql://localhost:5432/', pgUser, pgPassword, 'org.postgresql.Driver') + sql.execute("CREATE DATABASE ${dbName}") } } task dropPGDB { - description= "Drops the specified PostgreSQL database. The database name has to be passed (like: -PdbName=someDBname)" + description = 'Drops the specified PostgreSQL database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:postgresql://localhost:5432/', pgUser, pgPassword, 'org.postgresql.Driver' ) - sql.execute( 'DROP DATABASE '+ "$dbName") + def sql = Sql.newInstance('jdbc:postgresql://localhost:5432/', pgUser, pgPassword, 'org.postgresql.Driver') + sql.execute("DROP DATABASE ${dbName}") } } task createMySQLDB { - description= "Creates the MySQL Database. Needs database name to be passed (like: -PdbName=someDBname)" + description = 'Creates the MySQL Database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.cj.jdbc.Driver' ) - sql.execute( 'CREATE DATABASE '+"`$dbName` CHARACTER SET utf8mb4" ) + def sql = Sql.newInstance('jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.cj.jdbc.Driver') + sql.execute("CREATE DATABASE `${dbName}` CHARACTER SET utf8mb4") } } task dropMySQLDB { - description= "Drops the specified MySQL database. The database name has to be passed (like: -PdbName=someDBname)" + description = 'Drops the specified MySQL database. Needs database name to be passed (e.g., -PdbName=someDBname)' doLast { - def sql = Sql.newInstance( 'jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.cj.jdbc.Driver' ) - sql.execute( 'DROP DATABASE '+"`$dbName`") - } -} - -task setBlankPassword { - doLast { - def sql = Sql.newInstance( 'jdbc:mariadb://localhost:3306/', mysqlUser, mysqlPassword, 'org.mariadb.jdbc.Driver' ) - sql.execute('USE `fineract_tenants`') - sql.execute('UPDATE fineract_tenants.tenants SET schema_server = \'localhost\', schema_server_port = \'3306\', schema_username = \'mifos\', schema_password = \'mysql\' WHERE id=1;') + def sql = Sql.newInstance('jdbc:mysql://localhost:3306/', mysqlUser, mysqlPassword, 'com.mysql.cj.jdbc.Driver') + sql.execute("DROP DATABASE `${dbName}`") } } @@ -221,11 +190,6 @@ bootRun { jvmArgs = [ "-Dspring.output.ansi.enabled=ALWAYS" ] - - dependencies { - implementation 'org.mariadb.jdbc:mariadb-java-client' - implementation 'org.postgresql:postgresql' - } } springBoot { @@ -235,7 +199,11 @@ springBoot { bootJar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE manifest { - attributes('Main-Class': 'org.springframework.boot.loader.launch.PropertiesLauncher', 'Implementation-Title': 'Apache Fineract', 'Implementation-Version': project.version) + attributes( + 'Main-Class': 'org.springframework.boot.loader.launch.PropertiesLauncher', + 'Implementation-Title': 'Apache Fineract', + 'Implementation-Version': project.version + ) } archiveClassifier = '' dependsOn resolve @@ -246,20 +214,15 @@ jib { image = 'azul/zulu-openjdk-alpine:17' platforms { platform { - architecture = System.getProperty("os.arch").equals("aarch64")?"arm64":"amd64" + architecture = System.getProperty("os.arch") == 'aarch64' ? 'arm64' : 'amd64' os = 'linux' } } } - to { image = 'fineract' - tags = [ - "${project.version}", - 'latest' - ] + tags = [project.version, 'latest'] } - container { creationTime = 'USE_CURRENT_TIMESTAMP' mainClass = 'org.apache.fineract.ServerApplication' @@ -270,18 +233,11 @@ jib { '-Duser.timezone=UTC', '-Djava.security.egd=file:/dev/./urandom' ] - ports = ['8080/tcp', '8443/tcp'] + ports = ['8080', '8443'] labels = [maintainer: 'Aleksandar Vidakovic '] user = 'nobody:nogroup' } - allowInsecureRegistries = true - - dependencies { - implementation 'org.mariadb.jdbc:mariadb-java-client' - implementation 'org.postgresql:postgresql' - } - pluginExtensions { pluginExtension { implementation = 'com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension' @@ -298,18 +254,16 @@ jib { task migrateDatabase { doFirst { - println 'Executing liquibase database migration to version '+"$dbVersion" - - def dbUrl='jdbc:'+"$dbType"+'://'+"$dbHost"+':'+"$dbPort"+'/'+"$dbName" - def changeLogFilePath='fineract-provider/src/main/resources/db/changelog/tenant/upgrades/0000_upgrade_to_'+"$dbVersion"+'.xml' - + println "Executing liquibase database migration to version $dbVersion" + def dbUrl = "jdbc:${dbType}://${dbHost}:${dbPort}/${dbName}" + def changeLogFilePath = "src/main/resources/db/changelog/tenant/upgrades/0000_upgrade_to_${dbVersion}.xml" liquibase { activities { main { changeLogFile changeLogFilePath url dbUrl - username project.ext.mysqlUser - password project.ext.mysqlPassword + username mysqlUser + password mysqlPassword } } } @@ -328,27 +282,23 @@ cucumber { ] } -tasks.jibDockerBuild.dependsOn(bootJar) +tasks.jibDockerBuild.dependsOn bootJar -// Configuration for git properties gradle plugin -// https://github.com/n0mer/gradle-git-properties gitProperties { gitPropertiesResourceDir = file("$buildDir/classes/java/main") dateFormat = "yyyy-MM-dd'T'HH:mmZ" - dateFormatTimeZone = "GMT" + dateFormatTimeZone = 'GMT' failOnNoGitDirectory = false } -// make sure the generateGitProperties task always executes (even when git.properties is not changed) -generateGitProperties.outputs.upToDateWhen { false } +//generateGitProperties.outputs.upToDateWhen { false } -// NOTE: Gradle suggested these dependencies +// Ensure tasks execute in the correct order jar.dependsOn resolve test.dependsOn resolve checkstyleMain.dependsOn resolve checkstyleTest.dependsOn resolve rat.dependsOn prepareInputYaml spotbugsTest.dependsOn resolve -compileTestJava.dependsOn ':fineract-client:processResources', ':fineract-avro-schemas:processResources' -resolveMainClassName.dependsOn resolve processResources.dependsOn compileJava +resolveMainClassName.dependsOn resolve diff --git a/gradle.properties b/gradle.properties index d2b7f204fff..2b24fa693a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. # -org.gradle.jvmargs=-Xmx6g --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.management/javax.management=ALL-UNNAMED --add-opens=java.naming/javax.naming=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=null -buildType=BUILD +org.gradle.daemon=true +org.gradle.jvmargs=-Xmx6g org.gradle.caching=true org.gradle.parallel=true