From 479b0e561e11e9e35a172dcc43889e51cee79c04 Mon Sep 17 00:00:00 2001 From: gsidhwani_nr Date: Wed, 16 Oct 2024 16:51:09 +0530 Subject: [PATCH] fix: added publishing jar with depedencies --- custom-log4j-appender/build.gradle | 25 ++-- custom-log4j-appender/pom-template.xml | 31 +++++ custom-log4j-appender/publish-jar.sh | 159 +++++++++++++++++++++++++ 3 files changed, 203 insertions(+), 12 deletions(-) create mode 100644 custom-log4j-appender/pom-template.xml create mode 100755 custom-log4j-appender/publish-jar.sh diff --git a/custom-log4j-appender/build.gradle b/custom-log4j-appender/build.gradle index 7b40c3c..707501f 100644 --- a/custom-log4j-appender/build.gradle +++ b/custom-log4j-appender/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java' - id 'com.github.johnrengelman.shadow' version '6.1.0' id 'maven-publish' } @@ -16,14 +15,13 @@ dependencies { } jar { - enabled = false // Disable the standard JAR task -} - -shadowJar { - archiveClassifier.set('') // Remove the 'all' classifier - mergeServiceFiles() manifest { - attributes 'Main-Class': 'com.newrelic.labs.logforwarder.MAIN' + attributes( + 'Implementation-Title': 'Custom Log4j Appender', + 'Implementation-Vendor': 'New Relic Labs', + 'Implementation-Vendor-Id': 'com.newrelic.labs', + 'Implementation-Version': '1.0.2' + ) } } @@ -41,20 +39,23 @@ task sourcesJar(type: Jar) { from sourceSets.main.allSource } + + publishing { publications { mavenJava(MavenPublication) { - artifact shadowJar // Only include Shadow JAR + from components.java // Include standard JAR + artifact javadocJar artifact sourcesJar groupId = 'io.github.newrelic-experimental' artifactId = 'custom-log4j-appender' - version = '1.0.0' + version = '1.0.2' pom { name = 'Custom Log4j Appender' - description = 'A custom Log4j appender for New Relic Labs.' + description = 'A custom Log4j appender for New Relic.' url = 'https://github.com/newrelic-experimental/newrelic-java-log4j-appender' licenses { license { @@ -66,7 +67,7 @@ publishing { developer { id = 'newrelic' name = 'New Relic' - email = 'info@newrelic.com' + email = 'gsidhwani@newrelic.com' } } scm { diff --git a/custom-log4j-appender/pom-template.xml b/custom-log4j-appender/pom-template.xml new file mode 100644 index 0000000..3ac39c5 --- /dev/null +++ b/custom-log4j-appender/pom-template.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + {{GROUP_ID}} + {{ARTIFACT_ID}} + {{VERSION}} + Custom Log4j Appender + A custom Log4j appender for New Relic Labs. + https://github.com/newrelic-experimental/newrelic-java-log4j-appender + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + newrelic + New Relic + gsidhwani@newrelic.com + + + + scm:git:git://github.com/newrelic-experimental/newrelic-java-log4j-appender.git + scm:git:ssh://github.com/newrelic-experimental/newrelic-java-log4j-appender.git + https://github.com/newrelic-experimental/newrelic-java-log4j-appender + + + {{DEPENDENCIES}} + + diff --git a/custom-log4j-appender/publish-jar.sh b/custom-log4j-appender/publish-jar.sh new file mode 100755 index 0000000..b414afd --- /dev/null +++ b/custom-log4j-appender/publish-jar.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +# Set variables +GROUP_ID="io.github.newrelic-experimental" +ARTIFACT_ID="custom-log4j-appender" +VERSION="1.0.2" +KEY_ID="0ED9FD74E81E6D83FAE25F235640EA0B1C631C6F" # Replace with your actual key ID + +# Get the current directory (assuming the script is run from the custom-log4j-appender directory) +CURRENT_DIR=$(pwd) +PROJECT_ROOT=$(dirname "$CURRENT_DIR") + +echo "Current Directory: $CURRENT_DIR" +echo "Project Root: $PROJECT_ROOT" + +# Clean and build the project +cd "$PROJECT_ROOT" +./gradlew clean build jar javadocJar sourcesJar generatePomFileForMavenJavaPublication + +# Navigate to the directory containing the artifacts +cd "$CURRENT_DIR/build/libs" + +# List the contents of the build/libs directory for debugging +echo "Contents of build/libs:" +ls -la + +# Find the files without version numbers +JAR_FILE="custom-log4j-appender.jar" +JAVADOC_FILE="custom-log4j-appender-javadoc.jar" +SOURCES_FILE="custom-log4j-appender-sources.jar" +POM_FILE="custom-log4j-appender-$VERSION.pom" + +echo "JAR File: $JAR_FILE" +echo "Javadoc File: $JAVADOC_FILE" +echo "Sources File: $SOURCES_FILE" +echo "POM File: $POM_FILE" + +# Check if the files exist before proceeding +if [ ! -f "$JAR_FILE" ] || [ ! -f "$JAVADOC_FILE" ] || [ ! -f "$SOURCES_FILE" ]; then + echo "One or more expected files are missing in build/libs" + ls -la + exit 1 +fi + +# Prepare the directory structure +TARGET_DIR="$CURRENT_DIR/io/github/newrelic-experimental/custom-log4j-appender/$VERSION" +mkdir -p $TARGET_DIR + +# Copy the built artifacts to the appropriate directory with version numbers +echo "Copying artifacts to $TARGET_DIR" +cp $JAR_FILE $TARGET_DIR/custom-log4j-appender-$VERSION.jar +cp $JAVADOC_FILE $TARGET_DIR/custom-log4j-appender-$VERSION-javadoc.jar +cp $SOURCES_FILE $TARGET_DIR/custom-log4j-appender-$VERSION-sources.jar + +# Navigate to the target directory +cd $TARGET_DIR + +# Generate checksums for the copied files +for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar; do + echo "Generating checksums for $file" + md5sum $file | awk '{ print $1 }' > $file.md5 + sha1sum $file | awk '{ print $1 }' > $file.sha1 +done + +# Generate GPG signatures using the specific key ID +for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar; do + echo "Generating GPG signature for $file" + gpg --local-user $KEY_ID --armor --detach-sign $file +done + +# Generate the dependencies section for the POM file +DEPENDENCIES=$(cat < + com.squareup.okhttp3 + okhttp + 4.9.3 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + compile + + + org.apache.logging.log4j + log4j-core + 2.14.1 + compile + + + org.apache.logging.log4j + log4j-api + 2.14.1 + compile + + + com.squareup.okhttp3 + okhttp + 4.9.3 + runtime + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + runtime + + + org.apache.logging.log4j + log4j-core + 2.14.1 + runtime + + + org.apache.logging.log4j + log4j-api + 2.14.1 + runtime + +EOF +) + +# Read the POM template, replace placeholders, and save the final POM file +POM_TEMPLATE=$(<"$CURRENT_DIR/pom-template.xml") +POM_CONTENT="${POM_TEMPLATE//\{\{GROUP_ID\}\}/$GROUP_ID}" +POM_CONTENT="${POM_CONTENT//\{\{ARTIFACT_ID\}\}/$ARTIFACT_ID}" +POM_CONTENT="${POM_CONTENT//\{\{VERSION\}\}/$VERSION}" +POM_CONTENT="${POM_CONTENT//\{\{DEPENDENCIES\}\}/$DEPENDENCIES}" + +echo "$POM_CONTENT" > "$TARGET_DIR/$POM_FILE" + +# Generate checksums and signatures for the POM file +echo "Generating checksums and GPG signature for $POM_FILE" +md5sum $POM_FILE | awk '{ print $1 }' > $POM_FILE.md5 +sha1sum $POM_FILE | awk '{ print $1 }' > $POM_FILE.sha1 +gpg --local-user $KEY_ID --armor --detach-sign $POM_FILE + +# Verify checksums +echo "Verifying checksums" +for file in custom-log4j-appender-$VERSION.jar custom-log4j-appender-$VERSION-javadoc.jar custom-log4j-appender-$VERSION-sources.jar $POM_FILE; do + if [ -f "$file" ]; then + echo "Verifying checksum for $file" + md5sum -c <(echo "$(cat $file.md5) $file") + sha1sum -c <(echo "$(cat $file.sha1) $file") + else + echo "File $file does not exist in the target directory $TARGET_DIR." + ls -la $TARGET_DIR + fi +done + +# Navigate back to the custom-log4j-appender directory +cd "$CURRENT_DIR" + +# Create a ZIP file containing the entire directory structure +echo "Creating ZIP file custom-log4j-appender-$VERSION.zip" +zip -r custom-log4j-appender-$VERSION.zip io + +echo "Artifacts prepared and zipped successfully. You can now upload custom-log4j-appender-$VERSION.zip to Sonatype OSSRH."