Skip to content

Commit

Permalink
Build script publishing code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
borisfox-redcom committed Aug 16, 2018
1 parent b76fd86 commit e73b693
Showing 1 changed file with 64 additions and 71 deletions.
135 changes: 64 additions & 71 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id 'net.linguica.maven-settings' version '0.5'
}

description = 'DaData API client for Java'
description = 'DaData.ru Standardization API client java library'
group = 'ru.redcom.lib'
version = '0.0.1'
sourceCompatibility = 1.8
Expand All @@ -19,21 +19,27 @@ ext {
springBootVersion = '2.0.4.RELEASE'
encoding = 'UTF-8'
// pom attributes
artifactName = name
artifactName = 'DaData.ru API client'
artifactDescription = description
mavenCentralPublishingURL = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
corporatePublishingURL = 'sftp://devel.ws.redcom.ru:22/var/spool/users/maven2'
organizationName = 'REDCOM-Internet'
organizationURLpath = 'github.com/redcom-internet'
organizationURL = 'https://' + organizationURLpath
organizationURLpath = 'redcom-internet'
organizationURL = 'https://github.com/' + organizationURLpath
projectRootURLpath = '/dadata-api-client'
projectRootURL = organizationURL + projectRootURLpath
projectIssueURL = projectRootURL + '/issues'
projectSCM = 'GitHub'
projectLicense = 'MIT License'
projectLicenseURL = projectRootURL + '/blob/master/LICENSE.txt'
projectSCMConnection = 'scm:git:git://' + organizationURLpath + projectRootURLpath + '.git'
projectDeveloper = 'Boris Fox'
projectSCMConnection = 'scm:git:git://github.com/' + organizationURLpath + projectRootURLpath + '.git'
projectSCMDeveloperConnection = 'scm:git:ssh://git@github.com:' + organizationURLpath + projectRootURLpath + '.git'
projectSCMURL = projectRootURL + '/tree/master'
developerId = 'boris'
developerName = 'Boris Fox'
developerEmail = 'boris@redcom.ru'
developerOrganization = organizationName
developerOrganizationURL = 'http://www.redcom.ru/'
}

// Manifest attributes for all archives
Expand All @@ -44,52 +50,6 @@ def sharedManifest = manifest {
'Build-Jdk': System.getProperty("java.version"))
}

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
resolveStrategy = DELEGATE_FIRST

description artifactDescription
name artifactName
url projectRootURL
organization {
name organizationName
url organizationURL
}
issueManagement {
system projectSCM
url projectIssueURL
}
licenses {
license {
name projectLicense
url projectLicenseURL
distribution 'repo'
}
}
scm {
url projectRootURL
connection projectSCMConnection
developerConnection projectSCMConnection
}
developers {
developer {
name projectDeveloper
}
}
}
}
}

defaultTasks 'build'

tasks.withType(JavaCompile).each { it.options.setEncoding("${project.ext.encoding}") }
Expand Down Expand Up @@ -136,6 +96,8 @@ test {
javadoc {
options.encoding = project.ext.encoding
options.charSet = project.ext.encoding
if(JavaVersion.current().isJava9Compatible())
options.addBooleanOption('html4', true)
}

// Binaries archive
Expand All @@ -158,9 +120,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}

artifacts {
archives jar
archives sourcesJar
archives javadocJar
archives sourcesJar, javadocJar
}

signing {
Expand All @@ -172,25 +132,58 @@ signing {
publishing {
publications {
mavenJava(MavenPublication) {
customizePom(pom)
from components.java

// create the sign pom artifact
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'
}
artifact sourcesJar
artifact javadocJar

// customize pom file
pom {
packaging = 'jar'
name = artifactName
description = artifactDescription
url = projectRootURL
organization {
name = organizationName
url = organizationURL
}
issueManagement {
system = projectSCM
url = projectIssueURL
}
licenses {
license {
name = projectLicense
url = projectLicenseURL
distribution = 'repo'
}
}
scm {
url = projectSCMURL
connection = projectSCMConnection
developerConnection = projectSCMDeveloperConnection
}
developers {
developer {
id = developerId
name = developerName
email = developerEmail
organization = developerOrganization
organizationUrl = developerOrganizationURL
}
}
}

artifact sourcesJar {
classifier = 'sources'
}
artifact javadocJar {
classifier = 'javadoc'
// create the sign pom artifact
pom.withXml {
def pomFile = file("${project.buildDir}/generated-pom.xml")
writeTo(pomFile)
//noinspection GroovyAssignabilityCheck
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
extension = 'pom.asc'
}
}

// create the signed artifacts
Expand Down Expand Up @@ -233,7 +226,7 @@ repositories {

dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-json', version: "$springBootVersion"
implementation group: 'org.projectlombok', name: 'lombok', version: '1.18.+'
implementation group: 'org.projectlombok', name: 'lombok', version: '[1.18,)'

testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "$springBootVersion"
testImplementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.+'
Expand Down

0 comments on commit e73b693

Please sign in to comment.