Skip to content

Commit 0bd947b

Browse files
committed
Gradle file and GitHub Actions added
1 parent 059f964 commit 0bd947b

3 files changed

Lines changed: 98 additions & 52 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Name of the workflow visible in the Actions tab
2+
name: Publish Release
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v*.*.*' # Triggers ONLY on push of semver tags (v0.1.3, v1.0.0, etc.)
8+
9+
permissions:
10+
contents: write # Allows creating/modifying releases and tags in the repo
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest # Free Linux VM, optimal for Gradle/Java
15+
16+
steps:
17+
# STEP 1: Clone the full repository
18+
- name: Checkout
19+
uses: actions/checkout@v4 # Official GitHub checkout action
20+
with:
21+
fetch-depth: 0 # Fetches FULL Git history (required for changelog)
22+
23+
# STEP 2: Install Java 25 (builds Java 8 compatible bytecode)
24+
- name: Setup Java
25+
uses: actions/setup-java@v4 # Official JDK setup action
26+
with:
27+
distribution: 'temurin' # Adoptium Temurin (open source, stable)
28+
java-version: '25' # Modern Java for faster builds
29+
30+
# STEP 3: Setup Gradle with intelligent caching
31+
- name: Setup Gradle
32+
uses: gradle/actions/setup-gradle@v4 # Official Gradle action
33+
# Auto-caches: ~/.gradle, dependencies, wrapper → reduces time from 10min to 1-2min
34+
35+
# STEP 4: Extract version from tag and pass to Gradle
36+
- name: Set version from tag
37+
run: echo "ORG_GRADLE_PROJECT_VERSION_NAME=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
38+
# Example: refs/tags/v0.1.3 → 0.1.3
39+
# Temporary override of 'version' in build.gradle.kts
40+
41+
# STEP 5: Build → Test → Javadoc → Signing → Upload → Auto-Release to Maven Central
42+
- name: Publish to Maven Central
43+
run: ./gradlew publishToMavenCentral --no-configuration-cache -Psign=true
44+
env:
45+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
46+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
47+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }}
48+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
49+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
50+
51+
# STEP 6: Create automatic GitHub Release with changelog
52+
#- name: Create GitHub Release
53+
# uses: softprops/action-gh-release@v2 # Popular release action
54+
# if: runner.os != 'Windows' # Skip on Windows (known bugs)
55+
# with:
56+
# generate_release_notes: true # Analyzes commits → auto changelog
57+
# env:
58+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Auto-generated GitHub token

build.gradle.kts

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ java.sourceCompatibility = JavaVersion.VERSION_1_8
88
java.targetCompatibility = JavaVersion.VERSION_1_8
99

1010
plugins {
11+
id("com.vanniktech.maven.publish") version "0.35.0"
1112
`java-library`
1213
`maven-publish`
1314
signing
@@ -23,7 +24,7 @@ dependencies {
2324
}
2425

2526
java {
26-
withJavadocJar()
27+
//withJavadocJar() // Removed to avoid double signing
2728
withSourcesJar()
2829
}
2930

@@ -42,60 +43,47 @@ tasks.named<Test>("test") {
4243
useJUnitPlatform()
4344
}
4445

45-
publishing {
46-
repositories {
47-
maven {
48-
name = "Sonatype"
49-
val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
50-
val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots"
51-
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
52-
credentials {
53-
username = (properties["ossrhToken"] as String?)
54-
password = (properties["ossrhTokenPassword"] as String?)
55-
}
56-
}
57-
maven {
58-
name = "Local"
59-
val releasesRepoUrl = layout.buildDirectory.dir("repos/releases")
60-
val snapshotsRepoUrl = layout.buildDirectory.dir("repos/snapshots")
61-
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
62-
}
46+
// ✅ FIX ESATTO PER GRADLE 9.2.1 + vanniktech.maven.publish 0.35.0
47+
afterEvaluate {
48+
val plainJavadocJarTask = tasks.findByName("plainJavadocJar")
49+
val metadataTask = tasks.findByName("generateMetadataFileForMavenPublication")
50+
51+
if (plainJavadocJarTask != null && metadataTask != null) {
52+
metadataTask.dependsOn(plainJavadocJarTask)
6353
}
64-
publications.create<MavenPublication>("WLDTRelease") {
65-
from(components["java"])
54+
}
6655

67-
pom {
68-
name = "WLDT Core"
69-
url = "https://wldt.github.io/"
70-
description = project.description;
71-
licenses {
72-
license {
73-
name = "Apache-2.0 license"
74-
url = "https://raw.githubusercontent.com/wldt/wldt-core-java/master/LICENSE"
75-
}
76-
}
56+
mavenPublishing {
57+
coordinates(group.toString(), name.toString(), version.toString())
7758

78-
developers {
79-
developer {
80-
id = "piconem"
81-
name = "Marco Picone"
82-
email = "picone.m@gmail.com"
83-
}
84-
developer {
85-
id = "samubura"
86-
name = "Samuele Burattini"
87-
email = "samuele.burattini@unibo.it"
88-
}
59+
pom {
60+
name.set("WLDT Core")
61+
description.set("The WLDT Core Java Module to build Digital Twins")
62+
inceptionYear.set("2025")
63+
url.set("https://github.com/wldt/wldt-core-java")
64+
licenses {
65+
license {
66+
name.set("WLDT License")
67+
url.set("https://github.com/wldt/wldt-core-java/blob/main/LICENSE")
68+
distribution.set("https://github.com/wldt/wldt-core-java/blob/main/LICENSE")
8969
}
90-
91-
scm {
92-
connection = "scm:git:https://github.com/wldt/wldt-core-java.git"
93-
url = "https://github.com/wldt/wldt-core-java"
70+
}
71+
developers {
72+
developer {
73+
id.set("piconem")
74+
name.set("Marco Picone")
75+
url.set("https://github.com/piconem")
76+
}
77+
developer {
78+
id.set("samubura")
79+
name.set("Samuele Burattini")
80+
url.set("https://github.com/samubura")
9481
}
9582
}
83+
scm {
84+
url.set("https://github.com/wldt/wldt-core-java")
85+
connection.set("scm:git:git://github.com/wldt/wldt-core-java.git")
86+
developerConnection.set("scm:git:ssh://git@github.com/wldt/wldt-core-java.git")
87+
}
9688
}
97-
}
98-
99-
signing {
100-
sign(publishing.publications["WLDTRelease"])
101-
}
89+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)