Skip to content

Commit 91b2cd9

Browse files
Merge pull request #20 from quantori/feature/create-cqp-build-plugin
feature/create gradle sign-publish plugin
2 parents b3f8751 + d0b77f0 commit 91b2cd9

File tree

4 files changed

+163
-172
lines changed

4 files changed

+163
-172
lines changed

cqp-build/build.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
group = "com.quantori.cqp-build"
6+
7+
repositories {
8+
mavenLocal()
9+
mavenCentral()
10+
}
11+
12+
gradlePlugin {
13+
plugins {
14+
create("cqpJavaLibrary") {
15+
id = "com.quantori.cqp-build"
16+
implementationClass = "com.quantori.cqp.build.CqpJavaLibraryPlugin"
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compileOnly(gradleApi())
23+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.quantori.cqp.build
2+
3+
import org.gradle.api.JavaVersion
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
import org.gradle.api.publish.maven.MavenPublication
7+
import org.gradle.api.plugins.JavaPluginExtension
8+
import org.gradle.api.plugins.JavaLibraryPlugin
9+
import org.gradle.external.javadoc.StandardJavadocDocletOptions
10+
import org.gradle.jvm.toolchain.JavaLanguageVersion
11+
import org.gradle.api.tasks.testing.Test
12+
import org.gradle.kotlin.dsl.*
13+
14+
class CqpJavaLibraryPlugin : Plugin<Project> {
15+
override fun apply(project: Project) {
16+
project.pluginManager.apply(JavaLibraryPlugin::class)
17+
project.pluginManager.apply("maven-publish")
18+
project.pluginManager.apply("signing")
19+
20+
project.group = "com.quantori"
21+
project.version = project.findProperty("version") ?: "0.0.1-SNAPSHOT"
22+
23+
project.repositories {
24+
mavenLocal()
25+
mavenCentral()
26+
}
27+
28+
project.extensions.configure<JavaPluginExtension> {
29+
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
30+
withSourcesJar()
31+
withJavadocJar()
32+
}
33+
34+
project.tasks.withType<org.gradle.api.tasks.javadoc.Javadoc>().configureEach {
35+
if (JavaVersion.current().isJava9Compatible) {
36+
(options as StandardJavadocDocletOptions).apply {
37+
addStringOption("Xdoclint:none", "-quiet")
38+
addBooleanOption("html5", true)
39+
}
40+
}
41+
}
42+
43+
project.extensions.configure<org.gradle.api.publish.PublishingExtension> {
44+
publications {
45+
create<MavenPublication>("mavenJava") {
46+
from(project.components["java"])
47+
48+
pom {
49+
artifactId = project.name
50+
name.set(project.name)
51+
description.set(project.description ?: "")
52+
url.set("https://github.com/quantori/chem-query-platform")
53+
54+
licenses {
55+
license {
56+
name.set("The Apache License, Version 2.0")
57+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
58+
}
59+
}
60+
61+
developers {
62+
developer {
63+
id.set("artem.chukin")
64+
name.set("Artem Chukin")
65+
email.set("artem.chukin@quantori.com")
66+
}
67+
developer {
68+
id.set("dmitriy.gusev")
69+
name.set("Dmitriy Gusev")
70+
email.set("dmitriy.gusev@quantori.com")
71+
}
72+
developer {
73+
id.set("valeriy.burmistrov")
74+
name.set("Valeriy Burmistrov")
75+
email.set("valeriy.burmistrov@quantori.com")
76+
}
77+
developer {
78+
id.set("boris.sukhodoev")
79+
name.set("Boris Sukhodoev")
80+
email.set("boris.sukhodoev@quantori.com")
81+
}
82+
}
83+
84+
scm {
85+
connection.set("scm:git:git://github.com/quantori/chem-query-platform.git")
86+
developerConnection.set("scm:git:ssh://github.com/quantori/chem-query-platform.git")
87+
url.set("https://github.com/quantori/chem-query-platform")
88+
}
89+
}
90+
}
91+
}
92+
93+
repositories {
94+
maven {
95+
val releasesRepoUrl = project.layout.buildDirectory.dir("repos/releases")
96+
val snapshotsRepoUrl = project.layout.buildDirectory.dir("repos/snapshots")
97+
url = project.uri(
98+
if (project.version.toString().endsWith("SNAPSHOT"))
99+
snapshotsRepoUrl
100+
else
101+
releasesRepoUrl
102+
)
103+
}
104+
}
105+
}
106+
107+
project.extensions.configure<org.gradle.plugins.signing.SigningExtension> {
108+
setRequired {
109+
!project.version.toString().endsWith("SNAPSHOT") &&
110+
project.gradle.taskGraph.hasTask("publish")
111+
}
112+
113+
val signingSecretKey = project.findProperty("signing.secretKey") as String?
114+
?: System.getenv("GPG_SIGNING_SECRET_KEY")
115+
val signingPassword = project.findProperty("signing.password") as String?
116+
?: System.getenv("GPG_SIGNING_PASSWORD")
117+
118+
if (!signingSecretKey.isNullOrBlank() && !signingPassword.isNullOrBlank()) {
119+
useInMemoryPgpKeys(signingSecretKey, signingPassword)
120+
121+
sign(project.configurations.getByName("archives"))
122+
sign(project.extensions.getByType(org.gradle.api.publish.PublishingExtension::class).publications["mavenJava"])
123+
} else {
124+
project.logger.lifecycle("GPG signing skipped: missing credentials")
125+
}
126+
}
127+
128+
project.tasks.named("test", Test::class) {
129+
useJUnitPlatform()
130+
testLogging {
131+
events("passed", "skipped", "failed")
132+
}
133+
}
134+
}
135+
}

cqp-core/build.gradle.kts

Lines changed: 1 addition & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,12 @@
1-
import java.net.HttpURLConnection
2-
import kotlin.io.encoding.Base64
3-
import kotlin.io.encoding.ExperimentalEncodingApi
4-
51
plugins {
62
`java-library`
7-
`maven-publish`
8-
signing
93
id("com.diffplug.spotless") version "7.0.2"
4+
id("com.quantori.cqp-build")
105
}
116

12-
group = "com.quantori"
137
description = "Chem query platform. Compound quick search"
148
version = "0.0.10"
159

16-
repositories {
17-
mavenLocal()
18-
mavenCentral()
19-
}
20-
21-
java {
22-
toolchain {
23-
languageVersion = JavaLanguageVersion.of(17)
24-
}
25-
withSourcesJar()
26-
withJavadocJar()
27-
}
28-
29-
publishing {
30-
publications {
31-
create<MavenPublication>("mavenJava") {
32-
from(components["java"])
33-
34-
pom {
35-
artifactId = "cqp-core"
36-
name = project.name
37-
description = project.description
38-
packaging = "jar"
39-
url = "https://github.com/quantori/chem-query-platform"
40-
41-
licenses {
42-
license {
43-
name = "The Apache License, Version 2.0"
44-
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
45-
}
46-
}
47-
48-
developers {
49-
developer {
50-
id = "artem.chukin"
51-
name = "Artem Chukin"
52-
email = "artem.chukin@quantori.com"
53-
}
54-
developer {
55-
id = "dmitriy gusev"
56-
name = "Dmitriy Gusev"
57-
email = "dmitriy.gusev@quantori.com"
58-
}
59-
60-
developer {
61-
id = "valeriy burmistrov"
62-
name = "Valeriy Burmistrov"
63-
email = "valeriy.burmistrov@quantori.com"
64-
}
65-
66-
developer {
67-
id = "boris sukhodoev"
68-
name = "Boris Sukhodoev"
69-
email = "boris.sukhodoev@quantori.com"
70-
}
71-
}
72-
73-
scm {
74-
connection = "scm:git:git://github.com/quantori/chem-query-platform.git"
75-
developerConnection = "scm:git:ssh://github.com/quantori/chem-query-platform.git"
76-
url = "https://github.com/quantori/chem-query-platform"
77-
}
78-
}
79-
}
80-
}
81-
repositories {
82-
maven {
83-
name = "localStaging"
84-
// change URLs to point to your repos, e.g. http://my.org/repo
85-
val releasesRepoUrl = uri(layout.buildDirectory.dir("repos/releases"))
86-
val snapshotsRepoUrl = uri(layout.buildDirectory.dir("repos/snapshots"))
87-
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
88-
}
89-
}
90-
}
91-
92-
tasks.test {
93-
useJUnitPlatform()
94-
testLogging {
95-
events("passed", "skipped", "failed")
96-
}
97-
}
98-
99-
artifacts {
100-
archives(tasks.named("javadocJar"))
101-
archives(tasks.named("sourcesJar"))
102-
}
103-
104-
signing {
105-
setRequired {
106-
!version.toString().endsWith("SNAPSHOT") && gradle.taskGraph.hasTask("publish")
107-
}
108-
val signingSecretKey = findProperty("signing.secretKey") as String? ?: System.getenv("GPG_SIGNING_SECRET_KEY")
109-
val signingPassword = findProperty("signing.password") as String? ?: System.getenv("GPG_SIGNING_PASSWORD")
110-
111-
useInMemoryPgpKeys(signingSecretKey, signingPassword)
112-
sign(publishing.publications["mavenJava"])
113-
sign(configurations.archives.get())
114-
}
115-
116-
// Fix Javadoc warnings on JDK 9+ (optional but recommended)
117-
if (JavaVersion.current().isJava9Compatible) {
118-
tasks.withType<Javadoc>().configureEach {
119-
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
120-
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
121-
}
122-
}
123-
124-
@OptIn(ExperimentalEncodingApi::class)
125-
fun String.toBase64(): String {
126-
return Base64.encode(this.toByteArray(Charsets.UTF_8))
127-
}
128-
129-
val publishToLocalStaging = tasks.getByName("publishMavenJavaPublicationToLocalStagingRepository")
130-
131-
publishToLocalStaging.outputs.dir(layout.buildDirectory.dir("repos/releases"))
132-
133-
val zipBundle by tasks.registering(Zip::class) {
134-
archiveFileName = "central-bundle.zip"
135-
destinationDirectory = project.layout.buildDirectory.dir("distributions")
136-
inputs.files(publishToLocalStaging.outputs.files)
137-
from(publishToLocalStaging.outputs.files.files)
138-
}
139-
140-
val uploadToMavenCentral by tasks.registering {
141-
val url = uri("https://central.sonatype.com/api/v1/publisher/upload").toURL()
142-
val boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
143-
inputs.file(zipBundle.map { it.archiveFile }.get())
144-
doLast {
145-
val file = zipBundle.get().archiveFile.get().asFile
146-
val mavenCentralUsername =
147-
findProperty("mavenCentralUsername") as String? ?: System.getenv("MAVEN_CENTRAL_USERNAME")
148-
val mavenCentralPassword =
149-
findProperty("mavenCentralPassword") as String? ?: System.getenv("MAVEN_CENTRAL_PASSWORD")
150-
val token = "$mavenCentralUsername:$mavenCentralPassword\n".toBase64()
151-
152-
val connection = (url.openConnection() as HttpURLConnection).apply {
153-
requestMethod = "POST"
154-
doOutput = true
155-
setRequestProperty("Authorization", "Bearer $token")
156-
setRequestProperty("Content-Type", "multipart/form-data; boundary=$boundary")
157-
}
158-
159-
val outputStream = connection.outputStream
160-
outputStream.bufferedWriter().use { writer ->
161-
writer.append("--$boundary\r\n")
162-
writer.append("Content-Disposition: form-data; name=\"bundle\"; filename=\"${file.name}\"\r\n")
163-
writer.append("Content-Type: application/octet-stream\r\n\r\n")
164-
writer.flush()
165-
166-
file.inputStream().use { it.copyTo(outputStream) }
167-
168-
writer.append("\r\n--$boundary--\r\n")
169-
writer.flush()
170-
}
171-
172-
val responseCode = connection.responseCode
173-
println("Response Code: $responseCode")
174-
println("Response Message: ${connection.inputStream.bufferedReader().readText()}")
175-
}
176-
}
177-
178-
179-
180-
18110
dependencies {
18211
implementation("com.lightbend.akka.discovery:akka-discovery-aws-api_2.13:1.5.0-M1")
18312
implementation("com.typesafe.akka:akka-discovery_2.13:2.9.0-M2")

settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
plugins {
2+
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
3+
}
14
rootProject.name = "chem-query-platform"
25

36
include("cqp-core")
7+
includeBuild("cqp-build")

0 commit comments

Comments
 (0)