Skip to content

Commit 2b6bd7c

Browse files
committed
build system progress
1 parent 84709e5 commit 2b6bd7c

File tree

7 files changed

+245
-52
lines changed

7 files changed

+245
-52
lines changed

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish Java Libraries to Maven Central
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up JDK 11
13+
uses: actions/setup-java@v3
14+
with:
15+
java-version: '11'
16+
distribution: 'temurin'
17+
- name: Extract version
18+
id: extract_version
19+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
20+
- name: Build and publish Core, Client, and PubSub modules
21+
run: |
22+
chmod +x ./gradlew
23+
./gradlew publishAllPublicationsToSonatypeRepository -PreleaseVersion=${{ env.VERSION }}
24+
env:
25+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
26+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
27+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
28+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}

core/build.gradle

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ apply plugin: 'eclipse'
33
apply plugin: 'java'
44
apply plugin: 'com.diffplug.spotless'
55
apply plugin: 'maven-publish'
6+
apply plugin: 'signing'
67

78
group = 'com.fastcomments'
8-
version = '0.0.1'
9+
version = project.findProperty('releaseVersion') ?: '0.0.1-SNAPSHOT'
910

1011
buildscript {
1112
repositories {
@@ -35,14 +36,71 @@ jar {
3536
}
3637
}
3738

39+
java {
40+
withJavadocJar()
41+
withSourcesJar()
42+
}
43+
3844
publishing {
3945
publications {
4046
mavenJava(MavenPublication) {
4147
from components.java
48+
49+
pom {
50+
name = 'FastComments Java Core'
51+
description = 'Official FastComments Core Library for Java'
52+
url = 'https://github.com/FastComments/fastcomments-java'
53+
54+
licenses {
55+
license {
56+
name = 'MIT'
57+
}
58+
}
59+
60+
developers {
61+
developer {
62+
id = 'fastcomments'
63+
name = 'FastComments Team'
64+
65+
}
66+
}
67+
68+
scm {
69+
connection = 'scm:git:git://github.com/FastComments/fastcomments-java.git'
70+
developerConnection = 'scm:git:ssh://github.com/FastComments/fastcomments-java.git'
71+
url = 'https://github.com/FastComments/fastcomments-java'
72+
}
73+
}
74+
}
75+
}
76+
77+
repositories {
78+
maven {
79+
name = "sonatype"
80+
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
81+
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
82+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
83+
84+
credentials {
85+
username = findProperty('ossrhUsername') ?: System.getenv('OSSRH_USERNAME')
86+
password = findProperty('ossrhPassword') ?: System.getenv('OSSRH_PASSWORD')
87+
}
4288
}
4389
}
4490
}
4591

92+
signing {
93+
def signingKey = findProperty('signingKey') ?: System.getenv('SIGNING_KEY')
94+
def signingPassword = findProperty('signingPassword') ?: System.getenv('SIGNING_PASSWORD')
95+
96+
// Only sign if credentials are available (required for Maven Central, optional for local)
97+
required = signingKey != null && signingPassword != null
98+
if (required) {
99+
useInMemoryPgpKeys(signingKey, signingPassword)
100+
sign publishing.publications.mavenJava
101+
}
102+
}
103+
46104
if (hasProperty('target') && target == 'android') {
47105

48106
apply plugin: 'com.android.library'
@@ -105,15 +163,6 @@ if (hasProperty('target') && target == 'android') {
105163
sourceCompatibility = JavaVersion.VERSION_1_8
106164
targetCompatibility = JavaVersion.VERSION_1_8
107165

108-
publishing {
109-
publications {
110-
maven(MavenPublication) {
111-
artifactId = 'core'
112-
from components.java
113-
}
114-
}
115-
}
116-
117166
task execute(type: JavaExec) {
118167
main = System.getProperty('mainClass')
119168
classpath = sourceSets.main.runtimeClasspath
@@ -177,4 +226,4 @@ test {
177226

178227
tasks.register("prepareKotlinBuildScriptModel") {
179228
// No action needed; this stub allows the Kotlin DSL tooling to run without error.
180-
}
229+
}

gradle.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Publishing configuration
2+
# Will be overridden by -PreleaseVersion in GitHub Actions
3+
version=0.0.1-SNAPSHOT
4+
5+
# Gradle settings
6+
org.gradle.jvmargs=-Xmx2048m
7+
org.gradle.parallel=true

init-client.gradle

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
allprojects {
22
apply plugin: 'java'
33
apply plugin: 'maven-publish'
4+
apply plugin: 'signing'
5+
6+
// Use releaseVersion property if set, otherwise fallback to snapshot version
7+
project.version = project.findProperty('releaseVersion') ?: '0.0.1-SNAPSHOT'
8+
9+
java {
10+
withJavadocJar()
11+
withSourcesJar()
12+
}
413

514
jar {
615
manifest {
@@ -14,7 +23,60 @@ allprojects {
1423
publications {
1524
mavenJava(MavenPublication) {
1625
from components.java
26+
27+
pom {
28+
name = 'FastComments Java Client'
29+
description = 'Official FastComments API Client for Java'
30+
url = 'https://github.com/FastComments/fastcomments-java'
31+
32+
licenses {
33+
license {
34+
name = 'MIT'
35+
url = 'https://opensource.org/licenses/MIT'
36+
}
37+
}
38+
39+
developers {
40+
developer {
41+
id = 'fastcomments'
42+
name = 'FastComments Team'
43+
44+
}
45+
}
46+
47+
scm {
48+
connection = 'scm:git:git://github.com/FastComments/fastcomments-java.git'
49+
developerConnection = 'scm:git:ssh://github.com/FastComments/fastcomments-java.git'
50+
url = 'https://github.com/FastComments/fastcomments-java'
51+
}
52+
}
1753
}
1854
}
55+
56+
repositories {
57+
maven {
58+
name = "sonatype"
59+
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
60+
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
61+
url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
62+
63+
credentials {
64+
username = project.findProperty('ossrhUsername') ?: System.getenv('OSSRH_USERNAME')
65+
password = project.findProperty('ossrhPassword') ?: System.getenv('OSSRH_PASSWORD')
66+
}
67+
}
68+
}
69+
}
70+
71+
signing {
72+
def signingKey = project.findProperty('signingKey') ?: System.getenv('SIGNING_KEY')
73+
def signingPassword = project.findProperty('signingPassword') ?: System.getenv('SIGNING_PASSWORD')
74+
75+
// Only sign if credentials are available (required for Maven Central, optional for local)
76+
required = signingKey != null && signingPassword != null
77+
if (required) {
78+
useInMemoryPgpKeys(signingKey, signingPassword)
79+
sign publishing.publications.mavenJava
80+
}
1981
}
20-
}
82+
}

0 commit comments

Comments
 (0)