From 896963391b927924f4ed2a10490b6c77c619fe50 Mon Sep 17 00:00:00 2001 From: tharindu1st Date: Tue, 7 May 2024 18:34:03 +0530 Subject: [PATCH] fat jar enforcer --- common-gradle-scripts/java.gradle | 32 ------------ gateway/enforcer/Dockerfile | 5 +- gateway/enforcer/build.gradle | 3 +- .../org.wso2.apk.enforcer/build.gradle | 22 ++++++++ gateway/enforcer/resources/build.gradle | 51 ------------------- gateway/enforcer/settings.gradle | 1 - 6 files changed, 25 insertions(+), 89 deletions(-) delete mode 100644 gateway/enforcer/resources/build.gradle diff --git a/common-gradle-scripts/java.gradle b/common-gradle-scripts/java.gradle index 750c53a7d8..7da251277f 100644 --- a/common-gradle-scripts/java.gradle +++ b/common-gradle-scripts/java.gradle @@ -20,7 +20,6 @@ // apply plugin: 'com.github.spotbugs' apply plugin: 'jacoco' apply plugin: 'java' -apply plugin: 'maven-publish' java.sourceCompatibility = JavaVersion.VERSION_11 repositories { @@ -31,34 +30,3 @@ repositories { } } -jar { - into("META-INF/maven/$project.group/$project.name") { - from { generatePomFileForMavenPublication } - rename ".*", "pom.xml" - } -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - } - } - - repositories { - maven { - name 'nexus' - // TODO: define public nexus repositories - url = "https://maven.wso2.org/nexus/service/local/staging/deploy/maven2/" - credentials { - username rootProject.hasProperty("nexus_username") ? nexus_username : System.getenv("NEXUS_USERNAME") - password rootProject.hasProperty("nexus_password") ? nexus_password : System.getenv("NEXUS_PASSWORD") - } - allowInsecureProtocol = false - } - } -} - -tasks.named('build').configure { - finalizedBy publishToMavenLocal -} diff --git a/gateway/enforcer/Dockerfile b/gateway/enforcer/Dockerfile index 9b3008d578..62ed13dfb7 100644 --- a/gateway/enforcer/Dockerfile +++ b/gateway/enforcer/Dockerfile @@ -68,7 +68,7 @@ ARG APK_USER_GROUP_ID=10001 ARG APK_USER_HOME=/home/${APK_USER} ARG GRPC_HEALTH_PROBE_PATH=/bin/grpc_health_probe ARG TARGETARCH -ARG APK_VERSION=1.0-SNAPSHOT +ARG APK_VERSION=1.1.0-SNAPSHOT ENV VERSION=${APK_VERSION} ENV JAVA_OPTS="" @@ -127,5 +127,4 @@ COPY resources/check_health.sh . #todo add applicationinsights.json file and point it to the appInsightsAgent jar #Add the agent using JVM arg -javaagent:/home/wso2/conf/applicationinsights-agent-3.1.1.jar #Add the config file using System property -Dapplicationinsights.configuration.file=/home/wso2/conf/applicationinsights.json - -CMD java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="${ENFORCER_HOME}/logs/heap-dump.hprof" $JAVA_OPTS -Dlog4j.configurationFile="${ENFORCER_HOME}/conf/log4j2.properties" -DtracingEnabled="true" -cp "lib/*:lib/dropins/*" org.wso2.apk.enforcer.server.AuthServer +CMD java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="${ENFORCER_HOME}/logs/heap-dump.hprof" $JAVA_OPTS -Dlog4j.configurationFile="${ENFORCER_HOME}/conf/log4j2.properties" -DtracingEnabled="true" -jar lib/enforcer-${VERSION}.jar diff --git a/gateway/enforcer/build.gradle b/gateway/enforcer/build.gradle index f29997056a..79a1ae4ea3 100644 --- a/gateway/enforcer/build.gradle +++ b/gateway/enforcer/build.gradle @@ -34,7 +34,7 @@ release { } task build{ - dependsOn("resources:build") + dependsOn("org.wso2.apk.enforcer:build_enforcer") finalizedBy docker_build } @@ -45,7 +45,6 @@ allprojects { subprojects { apply from: "$rootDir/../../common-gradle-scripts/java.gradle" - afterReleaseBuild.dependsOn publish } tasks.named("afterReleaseBuild").configure { diff --git a/gateway/enforcer/org.wso2.apk.enforcer/build.gradle b/gateway/enforcer/org.wso2.apk.enforcer/build.gradle index 5a7bc193a7..21fdfe75ce 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/build.gradle +++ b/gateway/enforcer/org.wso2.apk.enforcer/build.gradle @@ -15,6 +15,10 @@ * */ +plugins { + id 'com.github.johnrengelman.shadow' version '7.1.0' +} + description = 'WSO2 APK Enforcer' sourceSets { @@ -95,3 +99,21 @@ dependencies { implementation libs.mockito.inline } } +shadowJar { + baseName = 'enforcer' + version = project.version + classifier = '' + + manifest { + attributes 'Main-Class': 'org.wso2.apk.enforcer.server.AuthServer' + } + mergeServiceFiles() +} +tasks.register("copyJar", Copy) { + from shadowJar.archivePath + into "../resources/lib" +} +tasks.register("build_enforcer"){ + dependsOn("shadowJar") + finalizedBy("copyJar") +} \ No newline at end of file diff --git a/gateway/enforcer/resources/build.gradle b/gateway/enforcer/resources/build.gradle deleted file mode 100644 index 5eff7d1496..0000000000 --- a/gateway/enforcer/resources/build.gradle +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -description = 'WSO2 Enforcer Distribution Resources' - -dependencies { - implementation project(':org.wso2.apk.enforcer') - implementation project(':org.wso2.apk.enforcer.commons') -} -tasks.register('copy_dependencies', Copy) { - dependsOn create_lib - from configurations.default - into "$projectDir/lib" - finalizedBy build -} - -tasks.register('create_lib') { - dependsOn delete_lib - finalizedBy copy_dependencies -} - -tasks.register('delete_lib', Delete) { - delete "$projectDir/lib" - finalizedBy create_lib -} - -tasks.named('build').configure { - dependsOn copy_dependencies -} - -configurations.implementation { - exclude group: 'jline' - exclude group: 'org.slf4j', module: 'slf4j-log4j12' - exclude group: 'org.apache.logging' - exclude group: 'log4j' - exclude group: 'org.ops4j.pax.logging' -} \ No newline at end of file diff --git a/gateway/enforcer/settings.gradle b/gateway/enforcer/settings.gradle index f838896316..07edaabf9f 100644 --- a/gateway/enforcer/settings.gradle +++ b/gateway/enforcer/settings.gradle @@ -18,7 +18,6 @@ rootProject.name = 'enforcer-parent' include(':org.wso2.apk.enforcer') include(':org.wso2.apk.enforcer.commons') - include(':resources') include(':org.wso2.apk.enforcer.analytics.publishers') dependencyResolutionManagement {