Migrating publishing to gradle

This commit is contained in:
Ziver Koc 2024-09-10 22:36:53 +02:00
parent f4cd76ef7d
commit bf34f79d19
3 changed files with 44 additions and 37 deletions

14
Jenkinsfile vendored
View file

@ -14,22 +14,20 @@ node {
} }
withMaven(mavenConfiguration) { withMaven(mavenConfiguration) {
def mvnParams = "-Dbuild.number=${BUILD_NUMBER} -Dbuild.development=false" def gradleParams = "--no-daemon -Pversion=1.0.${BUILD_NUMBER}"
stage('Build') { stage('Build') {
sh "mvn ${mvnParams} clean compile" sh "./gradlew ${gradleParams} -x test clean build"
} }
stage('Test') { stage('Test') {
sh "mvn ${mvnParams} test" sh "./gradlew ${gradleParams} test"
}
stage('Package') {
sh "mvn ${mvnParams} -DskipStatic -DskipTests package"
} }
stage('Deploy') { stage('Deploy') {
sh "mvn ${mvnParams} -DskipStatic -DskipTests deploy" sh "./gradlew ${gradleParams} publishToMavenLocal"
sh "./gradlew ${gradleParams} -Prelease publish"
sh "mvn ${mvnParams} scm:tag" sh "mvn ${mvnParams} scm:tag"
} }
} }

View file

@ -1,8 +1,10 @@
plugins { plugins {
id 'java' id 'java-library'
id 'maven-publish' id 'jacoco'
} }
apply from: 'build_publish.gradle'
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
@ -61,4 +63,4 @@ sourceSets {
srcDirs 'test' srcDirs 'test'
} }
} }
} }

View file

@ -1,12 +1,22 @@
// Documentation: https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_gradle // Documentation: https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_gradle
// Secrets stored in ~/.jreleaser/config.toml // Secrets stored in ~/.jreleaser/config.toml
apply plugin: 'maven-publish'
apply plugin: 'signing'
publishing { 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 { publications {
maven(MavenPublication) { mavenJava(MavenPublication) {
groupId = 'se.koc' groupId = 'se.koc'
artifactId = 'zutil' artifactId = 'zutil'
from components.java from components.java
pom { pom {
@ -34,31 +44,28 @@ publishing {
} }
} }
} }
}
repositories { // Signing
maven {
url = layout.buildDirectory.dir('staging-deploy') 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 { sourceSets.main.output.dir genOutputDir, builtBy: generateVersionTxt
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')
}
}
}
}
}