From 42d42e6dba601c7200711fcf149ea89bb4cf3676 Mon Sep 17 00:00:00 2001 From: Muthmainnah Date: Thu, 12 Aug 2021 11:15:01 +0700 Subject: [PATCH] feat: apply Maven changes to v1.6.1 --- .github/workflows/gradle.yml | 4 +- .github/workflows/publish.yml | 43 ++++++++ .gitignore | 2 + .settings/org.eclipse.buildship.core.prefs | 11 +++ build.gradle | 17 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- xendit-java-lib/build.gradle | 108 ++++++++++++++++++++- 7 files changed, 173 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index bced69c..14a023c 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -29,5 +29,5 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build + - name: Build and Sign with Gradle + run: ./gradlew build -x signArchives diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a16c68f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,43 @@ +name: Publish to Maven Central + +on: + push: + tags: + - 'v*' + +jobs: + publish: + name: Publish to Maven Central + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + name: Checkout + - name: Set up Java and Maven Central Repository + uses: actions/setup-java@v1 + with: + java-version: 1.11 + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - id: install-secret-key + name: Add secring.gpg + run: echo ${{ secrets.OSSRH_GPG }} | base64 -d > secring.gpg + - id: build-and-sign + name: Build and Sign with Gradle + run: ./gradlew build -x signArchives + - id: publish-to-central + name: Publish to central repository + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} + run: ./gradlew --stop && ./gradlew uploadArchives -Psigning.password=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} -Psigning.secretKeyRingFile=../secring.gpg -Psigning.keyId=${{ secrets.OSSRH_GPG_SECRET_KEY_ID }} --stacktrace --info + - name: Close and release repository + run: ./gradlew --stop && ./gradlew closeAndReleaseRepository + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} diff --git a/.gitignore b/.gitignore index deaefc0..19fe442 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,5 @@ bin/ ## OS X ############################## .DS_Store + +*.gpg diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index e889521..a1e2393 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true \ No newline at end of file diff --git a/build.gradle b/build.gradle index 76bde4e..c8d5d3a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ buildscript { } dependencies { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' + classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -29,14 +30,16 @@ ext { libraryDescription = 'Easily connect to Xendit with this library.' - siteUrl = 'https://github.com/xendit/xendit-java-library' - gitUrl = 'https://github.com/xendit/xendit-java-library.git' + siteUrl = 'https://github.com/xendit/xendit-java' + gitUrl = 'https://github.com/xendit/xendit-java.git' - developerId = 'hakiemaul' - developerName = 'Aulia Hakiem.' - developerEmail = 'hakiem@xendit.co' + developerId = '0505gonzalez' + developerName = 'Juan Gonzalez.' + developerEmail = 'juan@xendit.co' licenseName = 'MIT' - licenseUrl = '' + licenseUrl = 'https://opensource.org/licenses/MIT' allLicenses = ["MIT"] -} \ No newline at end of file +} + +apply plugin: 'io.codearte.nexus-staging' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b98dbe..d70f441 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip diff --git a/xendit-java-lib/build.gradle b/xendit-java-lib/build.gradle index a0e4b97..3302e71 100644 --- a/xendit-java-lib/build.gradle +++ b/xendit-java-lib/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'maven' + id 'signing' id 'maven-publish' id 'com.jfrog.bintray' id "com.diffplug.gradle.spotless" version "3.27.1" @@ -31,8 +32,19 @@ dependencies { testImplementation group: "org.mockito", name: "mockito-core", version:"3.1.0" } -task sourceJar(type: Jar) { - from sourceSets.main.allJava +task packageJavadoc(type: Jar, dependsOn: 'javadoc') { + from javadoc.destinationDir + classifier = 'javadoc' +} + +task sourcesJar(type: Jar) { + from sourceSets.main.allSource + classifier = 'sources' +} + +artifacts { + archives sourcesJar + archives packageJavadoc } publishing { @@ -42,7 +54,7 @@ publishing { artifactId artifact from components.java - artifact sourceJar { + artifact sourcesJar { classifier "sources" } pom { @@ -76,6 +88,13 @@ def bintrayUser = System.getenv('BINTRAY_USER') def bintrayAPIKey = System.getenv('BINTRAY_API_KEY') def bintrayGPGPassword = System.getenv('BINTRAY_GPG_PASSWORD') +String ossrhUser = System.getenv('OSSRH_USERNAME') +String ossrhPassword = System.getenv('OSSRH_PASSWORD') + +signing { + sign configurations.archives +} + bintray { user = bintrayUser key = bintrayAPIKey @@ -110,4 +129,85 @@ spotless { java { googleJavaFormat() } -} \ No newline at end of file +} + +publishing { + publications { + Production(MavenPublication) { + artifact("$buildDir/outputs/jar/xendit-java-release.jar") // replace with your library name + groupId this.group + artifactId 'xendit-java' // replace with your library artifact id + version this.version + + pom.withXml { + def dependenciesNode = asNode().appendNode('dependencies') + + // Iterate over the implementation dependencies (we don't want the test ones), + // adding a node for each + configurations.implementation.allDependencies.each { + // Ensure dependencies such as fileTree are not included in the pom. + if (it.name != 'unspecified') { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + } + } + } + } + } +} + + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUser, password: ossrhPassword) + } + + snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUser, password: ossrhPassword) + } + + pom.project { + name bintrayName + packaging 'jar' + // optionally artifactId can be defined here + description libraryDescription + url siteUrl + + scm { + connection gitUrl + developerConnection gitUrl + url gitUrl + } + + licenses { + license { + name licenseName + url licenseUrl + } + } + + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + } + } + } +} + +nexusStaging { + serverUrl = 'https://s01.oss.sonatype.org/service/local/' + username = ossrhUser + password = ossrhPassword + repositoryDescription = 'Closed and released using gradle script' + packageGroup = this.group +}