Skip to content

Commit 2baa2cf

Browse files
committed
Update project setup
1 parent 68abaaf commit 2baa2cf

File tree

10 files changed

+247
-158
lines changed

10 files changed

+247
-158
lines changed

PUBLISHING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Publishing
2+
3+
Keep Git tags with `vX.Y.Z-suffix` format. GitHub Actions job will only trigger on such tags and will remove `v` prefix.
4+
5+
See [`gradle-release.yml`](.github/workflows/gradle-release.yml) for whole publishing procedure.
6+
7+
Set the following environment variables in your CI/CD (GitHub Actions, etc.):
8+
9+
```txt
10+
# generated tokens on Sonatype account, do not use real username/password
11+
PUBLISHING_USERNAME=<username>
12+
PUBLISHING_PASSWORD=<password>
13+
14+
# generated PGP key for signing artifacts
15+
SIGNING_KEY=<PGP key>
16+
SIGNING_PASSWORD=<PGP password>
17+
```
18+
19+
Artifacts are published to Maven Central via Sonatype, using following Gradle task.
20+
21+
```bash
22+
./gradlew -Pversion=<version> -Psign publishAggregationToCentralPortal
23+
```
24+
25+
This command uses `nmcp` Gradle plugin - [link](https://github.com/GradleUp/nmcp).
26+
27+
**Note** that this only uploads the artifacts to Sonatype repository. You need to manually log in to Sonatype to push
28+
the artifacts to Maven Central.

build.gradle

Lines changed: 0 additions & 82 deletions
This file was deleted.

build.gradle.kts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import com.diffplug.spotless.LineEnding
2+
3+
plugins {
4+
id("java-library")
5+
id("maven-publish")
6+
id("signing")
7+
id("com.diffplug.spotless").version("7.2.1")
8+
id("com.gradleup.nmcp.aggregation").version("1.1.0")
9+
}
10+
11+
group = "io.github.malczuuu.problem4j"
12+
13+
/**
14+
* In order to avoid hardcoding snapshot versions, we derive the version from the current Git commit hash. For CI/CD add
15+
* -Pversion={releaseVersion} parameter to match Git tag.
16+
*/
17+
version =
18+
if (version == "unspecified")
19+
getSnapshotVersion(rootProject.rootDir)
20+
else
21+
version
22+
23+
java {
24+
toolchain.languageVersion = JavaLanguageVersion.of(8)
25+
withSourcesJar()
26+
withJavadocJar()
27+
}
28+
29+
repositories {
30+
mavenCentral()
31+
}
32+
33+
dependencies {
34+
testImplementation(platform("org.junit:junit-bom:5.13.4"))
35+
36+
testImplementation("org.junit.jupiter:junit-jupiter")
37+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
38+
}
39+
40+
publishing {
41+
publications {
42+
create<MavenPublication>("maven") {
43+
groupId = project.group.toString()
44+
artifactId = project.name
45+
version = project.version.toString()
46+
from(components["java"])
47+
48+
pom {
49+
name = project.name
50+
description = "Core library implementing Problem model according to RFC7807"
51+
url = "https://github.com/malczuuu/${project.name}"
52+
inceptionYear = "2025"
53+
licenses {
54+
license {
55+
name = "MIT License"
56+
url = "https://opensource.org/licenses/MIT"
57+
}
58+
}
59+
developers {
60+
developer {
61+
id = "malczuuu"
62+
name = "Damian Malczewski"
63+
url = "https://github.com/malczuuu"
64+
}
65+
}
66+
issueManagement {
67+
system = "GitHub Issues"
68+
url = "https://github.com/malczuuu/${project.name}/issues"
69+
}
70+
scm {
71+
connection = "scm:git:git://github.com/malczuuu/${project.name}.git"
72+
developerConnection = "scm:git:[email protected]:malczuuu/${project.name}.git"
73+
url = "https://github.com/malczuuu/${project.name}"
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
nmcpAggregation {
81+
centralPortal {
82+
username = System.getenv("PUBLISHING_USERNAME")
83+
password = System.getenv("PUBLISHING_PASSWORD")
84+
85+
publishingType = "USER_MANAGED"
86+
}
87+
publishAllProjectsProbablyBreakingProjectIsolation()
88+
}
89+
90+
signing {
91+
if (project.hasProperty("sign")) {
92+
useInMemoryPgpKeys(
93+
System.getenv("SIGNING_KEY"),
94+
System.getenv("SIGNING_PASSWORD")
95+
)
96+
sign(publishing.publications["maven"])
97+
}
98+
}
99+
100+
spotless {
101+
format("misc") {
102+
target("**/*.gradle.kts", "**/.gitattributes", "**/.gitignore")
103+
104+
trimTrailingWhitespace()
105+
leadingTabsToSpaces(4)
106+
endWithNewline()
107+
lineEndings = LineEnding.UNIX
108+
}
109+
110+
java {
111+
target("src/**/*.java")
112+
113+
googleJavaFormat("1.28.0")
114+
lineEndings = LineEnding.UNIX
115+
}
116+
}
117+
118+
tasks.register("printVersion") {
119+
doLast {
120+
println("Project version: $version")
121+
}
122+
}
123+
124+
tasks.withType<JavaCompile>().configureEach {
125+
options.compilerArgs.add("-parameters")
126+
}
127+
128+
/**
129+
* Disable doclint to avoid errors and warnings on missing JavaDoc comments.
130+
*/
131+
tasks.withType<Javadoc>().configureEach {
132+
(options as StandardJavadocDocletOptions).apply {
133+
addStringOption("Xdoclint:none", "-quiet")
134+
}
135+
}
136+
137+
tasks.withType<Test>().configureEach {
138+
useJUnitPlatform()
139+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "groovy"
2+
`kotlin-dsl`
33
}
44

55
repositories {
@@ -8,5 +8,4 @@ repositories {
88

99
dependencies {
1010
implementation("org.eclipse.jgit:org.eclipse.jgit:7.3.0.202506031305-r")
11-
implementation(localGroovy())
1211
}

buildSrc/src/main/groovy/Versioning.groovy

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import org.eclipse.jgit.revwalk.RevCommit
2+
import org.eclipse.jgit.revwalk.RevWalk
3+
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
4+
import java.io.File
5+
6+
private const val UNSPECIFIED = "unspecified"
7+
8+
/**
9+
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD.
10+
* On error, returns "unspecified".
11+
*
12+
* @param projectRootDir the root directory of the project (containing .git)
13+
*/
14+
fun getSnapshotVersion(projectRootDir: File): String {
15+
return try {
16+
val builder = FileRepositoryBuilder()
17+
.setGitDir(File(projectRootDir, ".git"))
18+
.readEnvironment()
19+
.findGitDir()
20+
21+
builder.build().use { repository ->
22+
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
23+
24+
RevWalk(repository).use { revWalk ->
25+
val headCommit: RevCommit = revWalk.parseCommit(headId)
26+
headCommit.id.name.substring(0, 7)
27+
}
28+
}
29+
} catch (e: Exception) {
30+
System.err.println("Error determining version: $e")
31+
UNSPECIFIED
32+
}
33+
}

gradle/wrapper/gradle-wrapper.jar

-8.75 KB
Binary file not shown.

0 commit comments

Comments
 (0)