From bf34f79d19aa4aa62abbdaef548945b4add4f3e2 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Tue, 10 Sep 2024 22:36:53 +0200 Subject: [PATCH] Migrating publishing to gradle --- Jenkinsfile | 14 +++++------ build.gradle | 8 +++--- build_publish.gradle | 59 +++++++++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fd7e0c0..d535b74 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,22 +14,20 @@ node { } withMaven(mavenConfiguration) { - def mvnParams = "-Dbuild.number=${BUILD_NUMBER} -Dbuild.development=false" + def gradleParams = "--no-daemon -Pversion=1.0.${BUILD_NUMBER}" stage('Build') { - sh "mvn ${mvnParams} clean compile" + sh "./gradlew ${gradleParams} -x test clean build" } stage('Test') { - sh "mvn ${mvnParams} test" - } - - stage('Package') { - sh "mvn ${mvnParams} -DskipStatic -DskipTests package" + sh "./gradlew ${gradleParams} test" } stage('Deploy') { - sh "mvn ${mvnParams} -DskipStatic -DskipTests deploy" + sh "./gradlew ${gradleParams} publishToMavenLocal" + sh "./gradlew ${gradleParams} -Prelease publish" + sh "mvn ${mvnParams} scm:tag" } } diff --git a/build.gradle b/build.gradle index 33ca367..1a0b3f1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,10 @@ plugins { - id 'java' - id 'maven-publish' + id 'java-library' + id 'jacoco' } +apply from: 'build_publish.gradle' + repositories { mavenLocal() mavenCentral() @@ -61,4 +63,4 @@ sourceSets { srcDirs 'test' } } -} \ No newline at end of file +} diff --git a/build_publish.gradle b/build_publish.gradle index 1ac6523..c04f371 100644 --- a/build_publish.gradle +++ b/build_publish.gradle @@ -1,12 +1,22 @@ // Documentation: https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_gradle // Secrets stored in ~/.jreleaser/config.toml +apply plugin: 'maven-publish' +apply plugin: 'signing' + publishing { + repositories { + maven { + def snapshotsRepoUrl = 'http://oss.sonatype.org/content/repositories/snapshots/' + def releasesRepoUrl = 'http://oss.sonatype.org/service/local/staging/deploy/maven2/' + url = project.hasProperty('release') && !version.endsWith('SNAPSHOT') ? releasesRepoUrl : snapshotsRepoUrl + } + } + publications { - maven(MavenPublication) { + mavenJava(MavenPublication) { groupId = 'se.koc' artifactId = 'zutil' - from components.java pom { @@ -34,31 +44,28 @@ publishing { } } } +} - repositories { - maven { - url = layout.buildDirectory.dir('staging-deploy') - } +// Signing + +signing { + sign publishing.publications.mavenJava +} + +// Generate version.txt + +ext.genOutputDir = file("${buildDir}/generated-resources") + +task generateVersionTxt() { + ext.outputFile = file("${genOutputDir}/version.txt") + outputs.file(outputFile) + doLast { + outputFile.text = """GroupId: ${project.group} +Name: ${project.name} +Version: ${version} +Build-time: ${java.time.LocalDateTime.now()} +""" } } -jreleaser { - signing { - active = 'ALWAYS' - armored = true - } - deploy { - maven { - nexus2 { - 'maven-central' { - active = 'ALWAYS' - url = 'https://s01.oss.sonatype.org/service/local' - snapshotUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' - closeRepository = true - releaseRepository = true - stagingRepository('build/staging-deploy') - } - } - } - } -} \ No newline at end of file +sourceSets.main.output.dir genOutputDir, builtBy: generateVersionTxt \ No newline at end of file