Skip to content

Improve gradle build files #363

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 3 commits into from
Jan 17, 2020
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
273 changes: 148 additions & 125 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ allprojects {
}

apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'


/* ******************** dependencies ******************** */
Expand Down Expand Up @@ -128,63 +129,70 @@ dependencies {

/* ******************** jars ******************** */

apply plugin: 'biz.aQute.bnd.builder'

jar {
bnd('Automatic-Module-Name': project.moduleName,
'Bundle-Name': project.name,
'Bundle-SymbolicName': project.moduleName,
'Bundle-Description': project.description,
'Bundle-Vendor': 'HiveMQ and the HiveMQ Community',
'Bundle-License': project.licenseShortName + ';description="' + project.licenseReadableName + '";link="' + project.licenseUrl + '"',
'Bundle-DocURL': project.docUrl,
'Bundle-SCM': 'url="' + project.githubUrl + '";connection="' + project.scmConnection + '";developerConnection="' + project.scmDeveloperConnection + '"',
'Export-Package': 'com.hivemq.client.annotations.*, com.hivemq.client.mqtt.*, com.hivemq.client.rx.*, com.hivemq.client.util.*',
'-consumer-policy': '${range;[==,=+)}',
'-removeheaders': 'Private-Package')
}
allprojects {
plugins.withType(JavaLibraryPlugin) {

project.apply plugin: 'biz.aQute.bnd.builder'

jar {
bnd(
'Automatic-Module-Name': project.moduleName,
'Bundle-Name': project.name,
'Bundle-SymbolicName': project.moduleName,
'Bundle-Description': project.description,
'Bundle-Vendor': 'HiveMQ and the HiveMQ Community',
'Bundle-License': project.licenseShortName + ';description="' + project.licenseReadableName + '";link="' + project.licenseUrl + '"',
'Bundle-DocURL': project.docUrl,
'Bundle-SCM': 'url="' + project.githubUrl + '";connection="' + project.scmConnection + '";developerConnection="' + project.scmDeveloperConnection + '"',
'Export-Package': 'com.hivemq.client.annotations.*, com.hivemq.client.mqtt.*, com.hivemq.client.rx.*, com.hivemq.client.util.*',
'-consumer-policy': '${range;[==,=+)}',
'-removeheaders': 'Private-Package')
}

apply plugin: 'com.github.johnrengelman.shadow'
task javadocJar(type: Jar) {
group 'documentation'
description 'Assembles a jar archive containing the javadoc.'

shadowJar {
appendix project.shadedAppendix
classifier null
from javadoc
classifier 'javadoc'
}

// api: not shaded and relocated, added as dependencies in pom
dependencies {
it.exclude(it.dependency('io.reactivex.rxjava2:rxjava'))
it.exclude(it.dependency('org.reactivestreams:reactive-streams'))
it.exclude(it.dependency('org.slf4j:slf4j-api'))
}
task sourcesJar(type: Jar) {
group 'build'
description 'Assembles a jar archive containing the main sources.'

def shadePrefix = project.group.toString() + '.shaded.'
def shadeFilePrefix = shadePrefix.replace('.', '_')
relocate 'io.netty', shadePrefix + 'io.netty'
relocate 'META-INF/native/libnetty', 'META-INF/native/lib' + shadeFilePrefix + 'netty'
exclude 'META-INF/io.netty.versions.properties'
relocate 'org.jctools', shadePrefix + 'org.jctools'
relocate 'org.jetbrains', shadePrefix + 'org.jetbrains'
relocate 'dagger', shadePrefix + 'dagger'
relocate 'javax.inject', shadePrefix + 'javax.inject'

minimize()
from sourceSets.main.allSource
classifier 'sources'
}
}
}

allprojects {
task javadocJar(type: Jar) {
group 'documentation'
description 'Assembles a jar archive containing the javadoc.'
plugins.withId('com.github.johnrengelman.shadow') {

from javadoc
classifier 'javadoc'
}
shadowJar {
appendix project.shadedAppendix
classifier null

task sourcesJar(type: Jar) {
group 'build'
description 'Assembles a jar archive containing the main sources.'
// api: not shaded and relocated, added as dependencies in pom
dependencies {
it.exclude(it.dependency('io.reactivex.rxjava2:rxjava'))
it.exclude(it.dependency('org.reactivestreams:reactive-streams'))
it.exclude(it.dependency('org.slf4j:slf4j-api'))
}

from sourceSets.main.allSource
classifier 'sources'
def shadePrefix = project.group.toString() + '.shaded.'
def shadeFilePrefix = shadePrefix.replace('.', '_')
relocate 'io.netty', shadePrefix + 'io.netty'
relocate 'META-INF/native/libnetty', 'META-INF/native/lib' + shadeFilePrefix + 'netty'
exclude 'META-INF/io.netty.versions.properties'
relocate 'org.jctools', shadePrefix + 'org.jctools'
relocate 'org.jetbrains', shadePrefix + 'org.jetbrains'
relocate 'dagger', shadePrefix + 'dagger'
relocate 'javax.inject', shadePrefix + 'javax.inject'

minimize()
}
}
}

Expand All @@ -193,93 +201,104 @@ allprojects {

apply from: "${project.rootDir}/gradle/publishing.gradle"

apply plugin: 'maven-publish'

void addPom(MavenPublication publication) {
publication.pom {
name = project.readableName
description = project.description
url = project.githubUrl
licenses {
license {
name = project.licenseReadableName
url = project.licenseUrl
}
}
developers {
developer {
id = 'SG'
name = 'Silvio Giebl'
email = '[email protected]'
allprojects {
plugins.withType(JavaLibraryPlugin) {

project.apply plugin: 'maven-publish'

publishing {
publications {
withType(MavenPublication) {
pom {
name = project.readableName
description = project.description
url = project.githubUrl
licenses {
license {
name = project.licenseReadableName
url = project.licenseUrl
}
}
developers {
developer {
id = 'SG'
name = 'Silvio Giebl'
email = '[email protected]'
}
}
scm {
connection = project.scmConnection
developerConnection = project.scmDeveloperConnection
url = project.githubUrl
}
issueManagement {
system = 'github'
url = project.issuesUrl
}
}
artifact javadocJar
artifact sourcesJar
}
normal(MavenPublication) {
from components.java
}
}
}
scm {
connection = project.scmConnection
developerConnection = project.scmDeveloperConnection
url = project.githubUrl
}
issueManagement {
system = 'github'
url = project.issuesUrl
}
}
}

publishing {
publications {
normal(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar
addPom(it)
}
shaded(MavenPublication) {
artifactId project.name + '-' + project.shadedAppendix
artifact shadowJar
artifact javadocJar
artifact sourcesJar
addPom(it)
pom.withXml { xml ->
def dependenciesNode = xml.asNode().appendNode('dependencies')

project.configurations.api.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'compile')
project.apply plugin: 'com.jfrog.bintray'

afterEvaluate {
bintray {
user = project.bintray_username
key = project.bintray_apiKey
publications = publishing.publications.withType(MavenPublication).stream().collect { it.name }
publish = true
pkg {
userOrg = 'hivemq'
repo = 'HiveMQ'
name = 'hivemq-mqtt-client'
desc = project.description
websiteUrl = project.githubUrl
issueTrackerUrl = project.issuesUrl
vcsUrl = project.githubUrl + '.git'
licenses = [project.licenseShortName]
labels = ['mqtt', 'mqtt-client', 'iot', 'internet-of-things', 'rxjava2', 'reactive-streams', 'backpressure']
version {
released = new Date()
gpg {
sign = true
}
/*mavenCentralSync {
user = ''
password = ''
}*/
}
}
}
}
}
}

apply plugin: 'com.jfrog.bintray'

bintray {
user = project.bintray_username
key = project.bintray_apiKey
publications = ['normal', 'shaded']
publish = true
pkg {
userOrg = 'hivemq'
repo = 'HiveMQ'
name = 'hivemq-mqtt-client'
desc = project.description
websiteUrl = project.githubUrl
issueTrackerUrl = project.issuesUrl
vcsUrl = project.githubUrl + '.git'
licenses = [project.licenseShortName]
labels = ['mqtt', 'mqtt-client', 'iot', 'internet-of-things', 'rxjava2', 'reactive-streams', 'backpressure']
version {
released = new Date()
gpg {
sign = true
allprojects {
plugins.withId('com.github.johnrengelman.shadow') {
publishing {
publications {
shaded(MavenPublication) {
artifactId project.name + '-' + project.shadedAppendix
artifact shadowJar
pom.withXml { xml ->
def dependenciesNode = xml.asNode().appendNode('dependencies')

project.configurations.api.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'compile')
}
}
}
}
/*mavenCentralSync {
user = ''
password = ''
}*/
}
}
}
Expand Down Expand Up @@ -314,4 +333,8 @@ allprojects {
}
}

apply from: "${project.rootDir}/gradle/japicc.gradle"
allprojects {
plugins.withType(JavaLibraryPlugin) {
project.apply from: "${project.rootDir}/gradle/japicc.gradle"
}
}
Loading