Skip to content

Commit

Permalink
build: moved to maven plugin for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSafonov committed Sep 1, 2019
1 parent 93a3782 commit 760ca2d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ out/
.idea/
*.log
*-dev.properties
gradle.properties
.pitest/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addons:
sonarcloud:
organization: "mikesafonov-github"
install:
- ./gradlew build
- ./gradlew build -x signArchives
script:
- sonar-scanner

Expand Down
139 changes: 40 additions & 99 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

apply plugin: "java-library"
apply plugin: "maven-publish"
apply plugin: "maven"
apply plugin: "signing"

ext { springBootVersion = "2.1.7.RELEASE" }
Expand Down Expand Up @@ -70,7 +70,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}

artifacts {
archives jar
archives sourceJar
archives javadocJar
}
Expand All @@ -84,7 +83,6 @@ jacoco {
}

test {
ignoreFailures = true
useJUnitPlatform()
finalizedBy jacocoTestReport
}
Expand All @@ -96,110 +94,53 @@ jacocoTestReport {
}
}

publishing {
publications {
mavenJava(MavenPublication) {
customizePom(pom)
groupId project.group
artifactId 'spring-boot-starter-prometheus-alerts'
version project.version
from components.java

pom.withXml {
def pomFile = file("${project.buildDir}/generated-pom.xml")
writeTo(pomFile)
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
extension = 'pom.asc'
}
}
// Build, sign, and upload
uploadArchives {
repositories {
mavenDeployer {

// Sign POM
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

artifact(sourceJar) {
classifier = 'sources'
}
artifact(javadocJar) {
classifier = 'javadoc'
// Destination
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}

project.tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
if (matcher.find()) {
classifier = matcher.group(1)
} else {
classifier = null
// Add required metadata to POM
pom.project {
name "spring-boot-starter-prometheus-alerts"
packaging "jar"
description "Starter for spring boot application witch catch alerts from Prometheus Alertmanager"
url "https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts"
organization {
name "com.github.mikesafonov"
url "https://github.com/MikeSafonov"
}
issueManagement {
system "GitHub"
url "https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts/issues"
}
licenses {
license {
name "MIT"
url "https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts/blob/master/LICENSE"
distribution "repo"
}
extension = 'jar.asc'
}
}
}
}
repositories {
maven {
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username sonatypeUsername
password sonatypePassword
}
}
}
}

def customizePom(pom) {
pom.withXml {
def root = asNode()

// eliminate test-scoped dependencies (no need in maven central POMs)
root.dependencies.removeAll { dep ->
dep.scope == "test"
}

// add all items necessary for maven central publication
root.children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST

description 'Starter for spring boot application witch catch alerts from Prometheus Alertmanager'
name 'spring-boot-starter-prometheus-alerts'
url 'https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts'
organization {
name 'com.github.mikesafonov'
url 'https://github.com/MikeSafonov'
}
issueManagement {
system 'GitHub'
url 'https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts/issues'
}
licenses {
license {
name 'MIT'
url 'https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts/blob/master/LICENSE'
distribution 'repo'
scm {
url "https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts"
connection "scm:git:git://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts.git"
developerConnection "scm:git:ssh://[email protected]:MikeSafonov/spring-boot-starter-prometheus-alerts.git"
}
}
scm {
url 'https://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts'
connection 'scm:git:git://github.com/MikeSafonov/spring-boot-starter-prometheus-alerts.git'
developerConnection 'scm:git:ssh://[email protected]:MikeSafonov/spring-boot-starter-prometheus-alerts.git'
}
developers {
developer {
name 'Mike Safonov'
developers {
developer {
name "Mike Safonov"
organization "com.github.mikesafonov"
organizationUrl "https://github.com/MikeSafonov"
}
}
}
}
}
}

model {
tasks.generatePomFileForMavenJavaPublication {
destination = file("$buildDir/generated-pom.xml")
}
tasks.publishMavenJavaPublicationToMavenLocal {
dependsOn project.tasks.signArchives
}
tasks.publishMavenJavaPublicationToMavenRepository {
dependsOn project.tasks.signArchives
}
}
}

0 comments on commit 760ca2d

Please sign in to comment.