@@ -2,16 +2,21 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22import java.net.URI
33
44plugins {
5- id(" maven-publish" )
65 kotlin(" jvm" ) version " 1.9.23"
76 `java- library`
7+ id(" org.jetbrains.dokka" ) version " 1.9.0"
8+ id(" eu.kakde.gradle.sonatype-maven-central-publisher" ) version " 1.0.6" // for sonatype central publishing
9+ `maven- publish` // for github-packages
10+ signing
811}
912
10- group = " com.phactum"
11- version = " 0.0.1"
13+ group = " com.phactum.lpm "
14+ version = " 0.0.1-SNAPSHOT "
1215
1316java {
1417 sourceCompatibility = JavaVersion .VERSION_17
18+ // withSourcesJar()
19+ // withJavadocJar()
1520}
1621
1722repositories {
@@ -37,9 +42,43 @@ kotlin {
3742 jvmToolchain(8 )
3843}
3944
40- publishing {
45+ // Use Dokka to generate KDoc-compatible Javadocs (optional, for Kotlin projects)
46+ tasks.register(" javadocJar" , Jar ::class ) {
47+ dependsOn(" dokkaHtml" ) // Generates Javadoc using Dokka
48+ archiveClassifier.set(" javadoc" )
49+ // from(tasks.named("dokkaHtml").get().outputDirectory)
50+ from(layout.buildDirectory.dir(" dokka" ))
51+ }
52+
53+ tasks.register(" sourcesJar" , Jar ::class ) {
54+ archiveClassifier.set(" sources" )
55+ from(sourceSets[" main" ].allSource)
56+ }
57+
58+ artifacts {
59+ archives(tasks.named(" sourcesJar" ))
60+ archives(tasks.named(" javadocJar" ))
61+ }
62+
63+ signing {
64+ val signingKey: String? by project
65+ val signingPassword: String? by project
66+ useInMemoryPgpKeys(signingKey, signingPassword)
67+ sign(configurations.archives.get())
68+ }
69+
70+
71+ /*
72+ Repository URL for snapshot deployment and download access:
4173
74+ https://s01.oss.sonatype.org/content/repositories/snapshots/
75+ Repository URL for release deployment, no download access! :
4276
77+ https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
78+ */
79+
80+ // github packages
81+ publishing {
4382
4483 repositories {
4584 maven {
@@ -50,15 +89,152 @@ publishing {
5089 password = System .getenv(" GITHUB_TOKEN" )
5190 }
5291 }
92+
5393 }
5494
5595 publications {
5696 register(" jar" , MavenPublication ::class ) {
5797 from(components[" java" ])
98+ artifact(tasks.named(" sourcesJar" ))
99+ artifact(tasks.named(" javadocJar" ))
58100 pom {
101+ name.set(" Lightweight Process Monitoring Common" )
102+ description.set(" A lightweight library for process monitoring." )
59103 url.set(" https://github.com/Phactum/lightweight-process-monitoring-common.git" )
104+ licenses {
105+ license {
106+ name.set(" The MIT License" )
107+ url.set(" https://opensource.org/licenses/MIT" )
108+ }
109+ }
110+ developers {
111+ developer {
112+ id.set(" phactum" )
113+ name.set(" Phactum Developers" )
114+ 115+ }
116+ }
117+ scm {
118+ connection.set(" scm:git:git://github.com/Phactum/lightweight-process-monitoring-common.git" )
119+ developerConnection.set(
" scm:git:ssh://[email protected] :Phactum/lightweight-process-monitoring-common.git" )
120+ url.set(" https://github.com/Phactum/lightweight-process-monitoring-common.git" )
121+ }
122+ }
123+ }
124+ }
125+
126+ }
127+ /*
128+ uploadArchives {
129+ repositories {
130+ mavenDeployer {
131+ beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
132+
133+ repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
134+ authentication(userName: ossrhUsername, password: ossrhPassword)
135+ }
136+
137+ snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
138+ authentication(userName: ossrhUsername, password: ossrhPassword)
139+ }
140+
141+ pom.project {
142+ name 'Example Application'
143+ packaging 'jar'
144+ // optionally artifactId can be defined here
145+ description 'A application used as an example on how to set up
146+ pushing its components to the Central Repository.'
147+ url 'http://www.example.com/example-application'
148+
149+ scm {
150+ connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
151+ developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
152+ url 'http://foo.googlecode.com/svn/trunk/'
153+ }
154+
155+ licenses {
156+ license {
157+ name 'The Apache License, Version 2.0'
158+ url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
159+ }
160+ }
161+
162+ developers {
163+ developer {
164+ id 'manfred'
165+ name 'Manfred Moser'
166+ 167+ }
168+ }
60169 }
61170 }
62171 }
172+ }
173+ */
174+
175+ // ------------------------------------
176+ // PUBLISHING TO SONATYPE CONFIGURATION
177+ // ------------------------------------
178+ object Meta {
179+ val COMPONENT_TYPE = " java" // "java" or "versionCatalog"
180+ val GROUP = project.group.toString()
181+ val ARTIFACT_ID = project.name
182+ val VERSION = project.version.toString()
183+ val URL = " https://github.com/Phactum/lightweight-process-monitoring-common.git"
184+ val PUBLISHING_TYPE = " USER_MANAGED" // USER_MANAGED or AUTOMATIC
185+ val SHA_ALGORITHMS = listOf (" SHA-256" , " SHA-512" ) // sha256 and sha512 are supported but not mandatory. Only sha1 is mandatory but it is supported by default.
186+ val DESC = " Test deployment only"
187+ val LICENSE = " MIT"
188+ val LICENSE_URL = " https://opensource.org/licenses/MIT"
189+ val GITHUB_REPO = " Phactum/lightweight-process-monitoring-common.git"
190+ val DEVELOPER_ID = " phactum-developer"
191+ val DEVELOPER_NAME = " Phactum Developer"
192+ val DEVELOPER_ORGANIZATION = " Phactum Softwareentwicklung GmbH"
193+ val DEVELOPER_ORGANIZATION_URL = " https://www.phactum.at/"
194+ }
63195
196+ val sonatypeUsername: String? by project // this is defined in ~/.gradle/gradle.properties
197+ val sonatypePassword: String? by project // this is defined in ~/.gradle/gradle.properties
198+
199+ sonatypeCentralPublishExtension {
200+ // Set group ID, artifact ID, version, and other publication details
201+ groupId.set(Meta .GROUP )
202+ artifactId.set(Meta .ARTIFACT_ID )
203+ version.set(Meta .VERSION )
204+ componentType.set(Meta .COMPONENT_TYPE ) // "java" or "versionCatalog"
205+ publishingType.set(Meta .PUBLISHING_TYPE ) // USER_MANAGED or AUTOMATIC
206+
207+ // Set username and password for Sonatype repository
208+ username.set(System .getenv(" SONATYPE_USERNAME" ) ? : sonatypeUsername)
209+ password.set(System .getenv(" SONATYPE_PASSWORD" ) ? : sonatypePassword)
210+
211+ // Configure POM metadata
212+ pom {
213+ name.set(Meta .ARTIFACT_ID )
214+ description.set(Meta .DESC )
215+ url.set(Meta .URL )
216+ licenses {
217+ license {
218+ name.set(Meta .LICENSE )
219+ url.set(Meta .LICENSE_URL )
220+ }
221+ }
222+ developers {
223+ developer {
224+ id.set(Meta .DEVELOPER_ID )
225+ name.set(Meta .DEVELOPER_NAME )
226+ organization.set(Meta .DEVELOPER_ORGANIZATION )
227+ organizationUrl.set(Meta .DEVELOPER_ORGANIZATION_URL )
228+ }
229+ }
230+ scm {
231+ url.set(" https://github.com/${Meta .GITHUB_REPO } " )
232+ connection.set(" scm:git:https://github.com/${Meta .GITHUB_REPO } " )
233+ developerConnection.set(" scm:git:https://github.com/${Meta .GITHUB_REPO } " )
234+ }
235+ issueManagement {
236+ system.set(" GitHub" )
237+ url.set(" https://github.com/${Meta .GITHUB_REPO } /issues" )
238+ }
239+ }
64240}
0 commit comments