Skip to content

Commit

Permalink
Adding gradle build config for publishing to maven central for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
tlf30 committed Dec 6, 2021
1 parent 5e265f3 commit 158954a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ bin/
libs/
build/
.gradle
.gradletasknamecache
.gradletasknamecache
/monkey-netty/publishing/publishing.properties
/monkey-netty/publishing/*.asc
/monkey-netty/publishing/*.gpg
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}

allprojects {
version = '0.1.2-SNAPSHOT'
group = "io.tlf.monkeynetty"
Expand Down
2 changes: 2 additions & 0 deletions monkey-netty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'maven-publish'
}

apply from: './publishing/publishing.gradle'

java {
withJavadocJar()
withSourcesJar()
Expand Down
107 changes: 107 additions & 0 deletions monkey-netty/publishing/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Create variables with empty default values

apply plugin: 'maven-publish'
apply plugin: 'signing'

ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''

ext {
PUBLISH_GROUP_ID = group
PUBLISH_VERSION = version
PUBLISH_ARTIFACT_ID = name
}

File secretPropsFile = project.rootProject.file('publishing/publishing.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

from components.java

artifact sourcesJar
artifact javadocJar

pom {
name = PUBLISH_ARTIFACT_ID
description = 'A implementation of a server-client communication system for jMonkeyEngine using Netty.IO that utilizes both TCP and UDP communication.'
url = 'https://github.com/tlf30/monkey-netty'
licenses {
license {
name = 'MIT'
url = 'https://github.com/tlf30/monkey-netty/blob/master/LICENSE'
}
}
developers {
developer {
id = 'tlf30'
name = 'Trevor Flynn'
email = '[email protected]'
}
}

scm {
connection = 'scm:git:github.com/tlf30/monkey-netty.git'
developerConnection = 'scm:git:ssh://github.com/tlf30/monkey-netty.git'
url = 'https://github.com/tlf30/monkey-netty/tree/master'
}
}
}
}
}
}

signing {
sign publishing.publications
}

0 comments on commit 158954a

Please sign in to comment.