Skip to content

Commit ba6354d

Browse files
Francesco VaianiFrancesco Vaiani
Francesco Vaiani
authored and
Francesco Vaiani
committed
Add support to Maven Repository publish
Signed-off-by: Francesco Vaiani <[email protected]>
1 parent 5019690 commit ba6354d

File tree

9 files changed

+133
-41
lines changed

9 files changed

+133
-41
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [1.0.0-rc.0] - Unreleased
8+
### Added
9+
- [generic] Support to Maven Repository publish
10+
811
### Changed
912
- [generic] Use ECDSA instead of RSA for key generation
1013

DeviceSDK/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ dependencies {
2727

2828
api 'joda-time:joda-time:2.9.7'
2929
}
30+
31+
ext {
32+
PUBLISH_GROUP_ID = project.group
33+
PUBLISH_VERSION = project.version
34+
PUBLISH_ARTIFACT_ID = 'devicesdk'
35+
}
36+
37+
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

DeviceSDKAndroid/build.gradle

-40
Original file line numberDiff line numberDiff line change
@@ -69,43 +69,3 @@ dependencies {
6969
androidTestImplementation 'org.mongodb:bson:3.11.0'
7070
androidTestImplementation 'com.squareup.okhttp3:okhttp:3.12.1'
7171
}
72-
73-
task androidSourcesJar(type: Jar) {
74-
archiveClassifier = 'sources'
75-
from android.sourceSets.main.java.srcDirs
76-
}
77-
78-
publishing {
79-
repositories {
80-
maven {
81-
url System.getenv('MAVEN_PUBLISH_URL')
82-
credentials {
83-
username System.getenv('MAVEN_PUBLISH_USERNAME')
84-
password System.getenv('MAVEN_PUBLISH_PASSWORD')
85-
}
86-
}
87-
}
88-
89-
publications {
90-
aar(MavenPublication) {
91-
groupId project.group
92-
artifactId "androiddevicesdk"
93-
version project.version
94-
95-
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
96-
artifact androidSourcesJar
97-
98-
pom.withXml {
99-
def dependencies = asNode().appendNode("dependencies")
100-
configurations.getByName("releaseRuntimeClasspath").getResolvedConfiguration()
101-
.getFirstLevelModuleDependencies().each {
102-
def dependency = dependencies.appendNode("dependency")
103-
dependency.appendNode("groupId", it.moduleGroup)
104-
dependency.appendNode("artifactId", it.moduleName)
105-
dependency.appendNode("version", it.moduleVersion)
106-
dependency.appendNode("scope", "runtime")
107-
}
108-
}
109-
}
110-
}
111-
}

DeviceSDKGeneric/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ test {
4242

4343
maxHeapSize = '1G'
4444
}
45+
46+
ext {
47+
PUBLISH_GROUP_ID = project.group
48+
PUBLISH_VERSION = project.version
49+
PUBLISH_ARTIFACT_ID = 'devicesdk-generic'
50+
}
51+
52+
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ buildscript {
1414

1515
plugins {
1616
id 'com.diffplug.spotless' version '5.5.1'
17+
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
1718
}
1819

1920
allprojects {
@@ -30,3 +31,5 @@ spotless {
3031
target '*.gradle', 'gradle/*.gradle'
3132
}
3233
}
34+
35+
apply from: "${rootDir}/scripts/publish-root.gradle"

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
org.gradle.jvmargs=-Xmx1536m
1010
java.util.logging.MemoryHandler.push=ALL
1111
version=1.0.0-beta.2
12-
group=org.astarteplatform
12+
group=org.astarte-platform
1313
org.gradle.parallel=false

keys/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/SECRET.gpg

scripts/publish-module.gradle

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
4+
task androidSourcesJar(type: Jar) {
5+
archiveClassifier.set('sources')
6+
if (project.plugins.findPlugin("com.android.library")) {
7+
from android.sourceSets.main.java.srcDirs
8+
} else {
9+
from sourceSets.main.java.srcDirs
10+
}
11+
}
12+
13+
task javadocJar(type: Jar) {
14+
from javadoc
15+
archiveClassifier.set('javadoc')
16+
}
17+
18+
artifacts {
19+
archives androidSourcesJar
20+
archives javadocJar
21+
}
22+
group = PUBLISH_GROUP_ID
23+
version = PUBLISH_VERSION
24+
25+
afterEvaluate {
26+
publishing {
27+
publications {
28+
release(MavenPublication) {
29+
groupId PUBLISH_GROUP_ID
30+
artifactId PUBLISH_ARTIFACT_ID
31+
version PUBLISH_VERSION
32+
if (project.plugins.findPlugin("com.android.library")) {
33+
from components.release
34+
} else {
35+
from components.java
36+
}
37+
38+
artifact androidSourcesJar
39+
artifact javadocJar
40+
41+
pom {
42+
name = PUBLISH_ARTIFACT_ID
43+
description = 'Astarte Java Device SDK'
44+
url = 'https://astarte-platform.org'
45+
licenses {
46+
license {
47+
name = 'Apache License 2.0'
48+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
49+
}
50+
}
51+
developers {
52+
developer {
53+
id = 'rbino'
54+
name = 'Riccardo Binetti'
55+
email = ' [email protected]'
56+
}
57+
}
58+
scm {
59+
connection = 'scm:git:github.com/astarte-platform/astarte-device-sdk-java.git'
60+
developerConnection = 'scm:git:ssh://github.com/astarte-platform/astarte-device-sdk-java.git'
61+
url = 'https://github.com/astarte-platform/astarte-device-sdk-java'
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}
68+
69+
ext["signing.keyId"] = rootProject.ext["signing.keyId"]
70+
ext["signing.password"] = rootProject.ext["signing.password"]
71+
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
72+
73+
signing {
74+
sign publishing.publications
75+
}

scripts/publish-root.gradle

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Create variables with empty default values
2+
ext["ossrhUsername"] = ''
3+
ext["ossrhPassword"] = ''
4+
ext["sonatypeStagingProfileId"] = ''
5+
ext["signing.keyId"] = ''
6+
ext["signing.password"] = ''
7+
ext["signing.secretKeyRingFile"] = ''
8+
9+
File secretPropsFile = project.rootProject.file('local.properties')
10+
if (secretPropsFile.exists()) {
11+
// Read local.properties file first if it exists
12+
Properties p = new Properties()
13+
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
14+
p.each { name, value -> ext[name] = value }
15+
} else {
16+
// Use system environment variables
17+
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
18+
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
19+
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
20+
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
21+
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
22+
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
23+
}
24+
25+
// Set up Sonatype repository
26+
nexusPublishing {
27+
repositories {
28+
sonatype {
29+
stagingProfileId = sonatypeStagingProfileId
30+
username = ossrhUsername
31+
password = ossrhPassword
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)