Skip to content

chore: migrate upload repository to maven-central from jcenter #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 77 additions & 63 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ plugins {
id 'nebula.optional-base' version '3.2.0'
id 'com.github.hierynomus.license' version '0.15.0'
id 'com.github.spotbugs' version "4.5.0"
id "com.jfrog.bintray" version "1.8.5"
}

allprojects {
group = 'com.optimizely.ab'
apply plugin: 'idea'
apply plugin: 'jacoco'

Expand All @@ -22,26 +20,27 @@ allprojects {
}
}

apply from: 'gradle/publish.gradle'

allprojects {
group = 'com.optimizely.ab'

def travis_defined_version = System.getenv('TRAVIS_TAG')
if (travis_defined_version != null) {
version = travis_defined_version
}
}

subprojects {
apply plugin: 'com.jfrog.bintray'
def publishedProjects = subprojects.findAll { it.name != 'java-quickstart' }

configure(publishedProjects) {
apply plugin: 'com.github.spotbugs'
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'me.champeau.gradle.jmh'
apply plugin: 'nebula.optional-base'
apply plugin: 'com.github.hierynomus.license'


sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand All @@ -62,11 +61,6 @@ subprojects {
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}

spotbugsMain {
reports {
xml.enabled = false
Expand Down Expand Up @@ -115,34 +109,42 @@ subprojects {
testCompile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
url 'https://github.com/optimizely/java-sdk'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'optimizely'
name 'Optimizely'
email 'developers@optimizely.com'
}
}
def docTitle = "Optimizely Java SDK"
if (name.equals('core-httpclient-impl')) {
docTitle = "Optimizely Java SDK: Httpclient"
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
customizePom(pom, docTitle)

from components.java
artifact sourcesJar
artifact javadocJar
}
}
repositories {
maven {
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username System.getenv('MAVEN_CENTRAL_USERNAME')
password System.getenv('MAVEN_CENTRAL_PASSWORD')
}
}
}
}

signing {
// skip signing for "local" version into MavenLocal for test-app
required { !version.equals("local") }

def signingKey = System.getenv('MAVEN_SIGNING_KEY')
def signingPassword = System.getenv('MAVEN_SIGNING_PASSPHRASE')
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.release
}
}

license {
Expand All @@ -153,42 +155,20 @@ subprojects {
ext.year = Calendar.getInstance().get(Calendar.YEAR)
}

def bintrayName = 'core-api';
if (name.equals('core-httpclient-impl')) {
bintrayName = 'httpclient'
}

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
pkg {
repo = 'optimizely'
name = "optimizely-sdk-${bintrayName}"
userOrg = 'optimizely'
version {
name = rootProject.version
}
publications = ['mavenJava']
}
}

build.dependsOn('generatePomFileForMavenJavaPublication')

bintrayUpload.dependsOn 'build'

task ship() {
dependsOn('bintrayUpload')
dependsOn('publish')
}

// concurrent publishing (maven-publish) causes an issue with maven-central repository
// - a single module splits into multiple staging repos, so validation fails.
// - adding this ordering requirement forces sequential publishing processes.
project(':core-api').javadocJar.mustRunAfter = [':core-httpclient-impl:ship']
}

task ship() {
dependsOn(':core-api:ship', ':core-httpclient-impl:ship')
}

// Only report code coverage for projects that are distributed
def publishedProjects = subprojects.findAll { it.path != ':simulator' }

task jacocoMerge(type: JacocoMerge) {
publishedProjects.each { subproject ->
executionData subproject.tasks.withType(Test)
Expand Down Expand Up @@ -225,3 +205,37 @@ tasks.coveralls {
dependsOn jacocoRootReport
onlyIf { System.env.'CI' && !JavaVersion.current().isJava9Compatible() }
}

// standard POM format required by MavenCentral

def customizePom(pom, title) {
pom.withXml {
asNode().children().last() + {
// keep this - otherwise some properties are not made into pom properly
resolveStrategy = Closure.DELEGATE_FIRST

name title
url 'https://github.com/optimizely/java-sdk'
description 'The Java SDK for Optimizely Full Stack (feature flag management for product development teams)'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'optimizely'
name 'Optimizely'
email 'optimizely-fullstack@optimizely.com'
}
}
scm {
connection 'scm:git:git://github.com/optimizely/java-sdk.git'
developerConnection 'scm:git:ssh:github.com/optimizely/java-sdk.git'
url 'https://github.com/optimizely/java-sdk.git'
}
}
}
}
2 changes: 2 additions & 0 deletions java-quickstart/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apply plugin: 'java'

dependencies {
compile project(':core-api')
compile project(':core-httpclient-impl')
Expand Down