@@ -7,7 +7,10 @@ buildscript {
7
7
8
8
plugins {
9
9
alias(libs.plugins.kotlin.jvm)
10
- // `maven-publish`
10
+ `java- library`
11
+ `maven- publish`
12
+ signing
13
+ alias(libs.plugins.nexusPublishPlugin)
11
14
}
12
15
13
16
val jvmTargetVersion: String by project
@@ -31,7 +34,6 @@ dependencies {
31
34
32
35
tasks {
33
36
java {
34
- withSourcesJar()
35
37
toolchain { languageVersion.set(JavaLanguageVersion .of(jvmTargetVersion)) }
36
38
}
37
39
@@ -40,20 +42,82 @@ tasks {
40
42
}
41
43
}
42
44
43
- // publishing {
44
- // repositories {
45
- // maven {
46
- // name = "GitHubPackages"
47
- // url = uri("https://maven.pkg.github.com/target/native_memory_allocator")
48
- // credentials {
49
- // username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
50
- // password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
51
- // }
52
- // }
53
- // }
54
- // publications {
55
- // register<MavenPublication>("gpr") {
56
- // from(components["java"])
57
- // }
58
- // }
59
- // }
45
+ java {
46
+ withJavadocJar()
47
+ withSourcesJar()
48
+ }
49
+
50
+ publishing {
51
+ repositories {
52
+ maven {
53
+ credentials(PasswordCredentials ::class )
54
+ name =
55
+ " sonatype" // correlates with the environment variable set in the github action release.yml publish job
56
+ val releasesRepoUrl = " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
57
+ val snapshotsRepoUrl = " https://s01.oss.sonatype.org/content/repositories/snapshots/"
58
+ setUrl(if (version.toString().endsWith(" SNAPSHOT" )) snapshotsRepoUrl else releasesRepoUrl)
59
+ }
60
+ }
61
+
62
+ publications {
63
+ val projectTitle: String by project
64
+ val projectDescription: String by project
65
+ val projectUrl: String by project
66
+ val projectScm: String by project
67
+
68
+ create<MavenPublication >(" mavenJava" ) {
69
+ artifactId = rootProject.name
70
+ from(components[" java" ])
71
+ versionMapping {
72
+ usage(" java-api" ) {
73
+ fromResolutionOf(" runtimeClasspath" )
74
+ }
75
+ usage(" java-runtime" ) {
76
+ fromResolutionResult()
77
+ }
78
+ }
79
+ pom {
80
+ name.set(projectTitle)
81
+ description.set(projectDescription)
82
+ url.set(projectUrl)
83
+ licenses {
84
+ license {
85
+ name.set(" Apache 2.0" )
86
+ url.set(" http://www.apache.org/licenses/LICENSE-2.0" )
87
+ }
88
+ }
89
+ developers {
90
+ developer {
91
+ id.set(" ossteam" )
92
+ name.set(" OSS Office" )
93
+
94
+ }
95
+ }
96
+ scm {
97
+ url.set(projectScm)
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ }
104
+
105
+ signing {
106
+ val signingKey: String? by project
107
+ val signingPassword: String? by project
108
+ if (signingKey.isNullOrBlank() || signingPassword.isNullOrBlank()) {
109
+ isRequired = false
110
+ } else {
111
+ useInMemoryPgpKeys(signingKey, signingPassword)
112
+ sign(publishing.publications)
113
+ }
114
+ }
115
+
116
+ nexusPublishing {
117
+ repositories {
118
+ sonatype {
119
+ nexusUrl.set(uri(" https://s01.oss.sonatype.org/service/local/" ))
120
+ snapshotRepositoryUrl.set(uri(" https://s01.oss.sonatype.org/content/repositories/snapshots/" ))
121
+ }
122
+ }
123
+ }
0 commit comments