Skip to content

Commit a40662c

Browse files
Extract publishing configuration to precompiled script plugin.
1 parent 0bebf9d commit a40662c

File tree

9 files changed

+125
-112
lines changed

9 files changed

+125
-112
lines changed

build.gradle.kts

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -64,109 +64,6 @@ allprojects {
6464
}
6565
}
6666

67-
// Make javadoc task errors not break the build, some are in third-party code.
68-
if (JavaVersion.current().isJava8Compatible) {
69-
allprojects {
70-
tasks.withType<Javadoc> {
71-
isFailOnError = false
72-
}
73-
}
74-
}
75-
76-
val projectNamesToPublish = listOf(
77-
"objectbox-java-api",
78-
"objectbox-java",
79-
"objectbox-kotlin",
80-
"objectbox-rxjava",
81-
"objectbox-rxjava3"
82-
)
83-
84-
fun hasSigningProperties(): Boolean {
85-
return (project.hasProperty("signingKeyId")
86-
&& project.hasProperty("signingKeyFile")
87-
&& project.hasProperty("signingPassword"))
88-
}
89-
90-
configure(subprojects.filter { projectNamesToPublish.contains(it.name) }) {
91-
apply(plugin = "maven-publish")
92-
apply(plugin = "signing")
93-
94-
configure<PublishingExtension> {
95-
repositories {
96-
maven {
97-
name = "GitLab"
98-
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPrivateToken")) {
99-
// "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
100-
val gitlabUrl = project.property("gitlabUrl")
101-
url = uri("$gitlabUrl/api/v4/projects/14/packages/maven")
102-
println("GitLab repository set to $url.")
103-
104-
credentials(HttpHeaderCredentials::class) {
105-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
106-
value = project.property("gitlabPrivateToken").toString()
107-
}
108-
authentication {
109-
create<HttpHeaderAuthentication>("header")
110-
}
111-
} else {
112-
println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set.")
113-
}
114-
}
115-
// Note: Sonatype repo created by publish-plugin.
116-
}
117-
118-
publications {
119-
create<MavenPublication>("mavenJava") {
120-
// Note: Projects set additional specific properties.
121-
pom {
122-
packaging = "jar"
123-
url.set("https://objectbox.io")
124-
licenses {
125-
license {
126-
name.set("The Apache Software License, Version 2.0")
127-
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
128-
distribution.set("repo")
129-
}
130-
}
131-
developers {
132-
developer {
133-
id.set("ObjectBox")
134-
name.set("ObjectBox")
135-
}
136-
}
137-
issueManagement {
138-
system.set("GitHub Issues")
139-
url.set("https://github.com/objectbox/objectbox-java/issues")
140-
}
141-
organization {
142-
name.set("ObjectBox Ltd.")
143-
url.set("https://objectbox.io")
144-
}
145-
scm {
146-
connection.set("scm:git@github.com:objectbox/objectbox-java.git")
147-
developerConnection.set("scm:git@github.com:objectbox/objectbox-java.git")
148-
url.set("https://github.com/objectbox/objectbox-java")
149-
}
150-
}
151-
}
152-
}
153-
}
154-
155-
configure<SigningExtension> {
156-
if (hasSigningProperties()) {
157-
val signingKey = File(project.property("signingKeyFile").toString()).readText()
158-
useInMemoryPgpKeys(
159-
project.property("signingKeyId").toString(),
160-
signingKey,
161-
project.property("signingPassword").toString()
162-
)
163-
sign((extensions.getByName("publishing") as PublishingExtension).publications["mavenJava"])
164-
} else {
165-
println("Signing information missing/incomplete for ${project.name}")
166-
}
167-
}
168-
}
169-
17067
tasks.wrapper {
17168
distributionType = Wrapper.DistributionType.ALL
17269
}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}

buildSrc/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Recommended to create, but keep empty
2+
// https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompiled_plugins
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
plugins {
2+
id("maven-publish")
3+
id("signing")
4+
}
5+
6+
// Make javadoc task errors not break the build, some are in third-party code.
7+
if (JavaVersion.current().isJava8Compatible) {
8+
tasks.withType<Javadoc> {
9+
isFailOnError = false
10+
}
11+
}
12+
13+
publishing {
14+
repositories {
15+
maven {
16+
name = "GitLab"
17+
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPrivateToken")) {
18+
// "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
19+
val gitlabUrl = project.property("gitlabUrl")
20+
url = uri("$gitlabUrl/api/v4/projects/14/packages/maven")
21+
println("GitLab repository set to $url.")
22+
23+
credentials(HttpHeaderCredentials::class) {
24+
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
25+
value = project.property("gitlabPrivateToken").toString()
26+
}
27+
authentication {
28+
create<HttpHeaderAuthentication>("header")
29+
}
30+
} else {
31+
println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set.")
32+
}
33+
}
34+
// Note: Sonatype repo created by publish-plugin, see root build.gradle.kts.
35+
}
36+
37+
publications {
38+
create<MavenPublication>("mavenJava") {
39+
// Note: Projects set additional specific properties.
40+
pom {
41+
packaging = "jar"
42+
url.set("https://objectbox.io")
43+
licenses {
44+
license {
45+
name.set("The Apache Software License, Version 2.0")
46+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
47+
distribution.set("repo")
48+
}
49+
}
50+
developers {
51+
developer {
52+
id.set("ObjectBox")
53+
name.set("ObjectBox")
54+
}
55+
}
56+
issueManagement {
57+
system.set("GitHub Issues")
58+
url.set("https://github.com/objectbox/objectbox-java/issues")
59+
}
60+
organization {
61+
name.set("ObjectBox Ltd.")
62+
url.set("https://objectbox.io")
63+
}
64+
scm {
65+
connection.set("scm:git@github.com:objectbox/objectbox-java.git")
66+
developerConnection.set("scm:git@github.com:objectbox/objectbox-java.git")
67+
url.set("https://github.com/objectbox/objectbox-java")
68+
}
69+
}
70+
}
71+
}
72+
}
73+
74+
signing {
75+
if (hasSigningProperties()) {
76+
val signingKey = File(project.property("signingKeyFile").toString()).readText()
77+
useInMemoryPgpKeys(
78+
project.property("signingKeyId").toString(),
79+
signingKey,
80+
project.property("signingPassword").toString()
81+
)
82+
sign(publishing.publications["mavenJava"])
83+
} else {
84+
println("Signing information missing/incomplete for ${project.name}")
85+
}
86+
}
87+
88+
fun hasSigningProperties(): Boolean {
89+
return (project.hasProperty("signingKeyId")
90+
&& project.hasProperty("signingKeyFile")
91+
&& project.hasProperty("signingPassword"))
92+
}

objectbox-java-api/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
apply plugin: 'java-library'
1+
plugins {
2+
id("java-library")
3+
id("objectbox-publish")
4+
}
25

36
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
47
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

objectbox-java/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
apply plugin: 'java-library'
2-
apply plugin: "com.github.spotbugs"
1+
plugins {
2+
id("java-library")
3+
id("objectbox-publish")
4+
id("com.github.spotbugs")
5+
}
36

47
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
58
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

objectbox-kotlin/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ buildscript {
22
ext.javadocDir = file("$buildDir/docs/javadoc")
33
}
44

5-
apply plugin: 'kotlin'
6-
apply plugin: 'org.jetbrains.dokka'
5+
plugins {
6+
id("kotlin")
7+
id("org.jetbrains.dokka")
8+
id("objectbox-publish")
9+
}
710

811
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
912
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

objectbox-rxjava/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
apply plugin: 'java-library'
1+
plugins {
2+
id("java-library")
3+
id("objectbox-publish")
4+
}
25

36
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
47
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

objectbox-rxjava3/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ buildscript {
22
ext.javadocDir = file("$buildDir/docs/javadoc")
33
}
44

5-
apply plugin: 'java-library'
6-
apply plugin: 'kotlin'
7-
apply plugin: 'org.jetbrains.dokka'
5+
plugins {
6+
id("java-library")
7+
id("kotlin")
8+
id("org.jetbrains.dokka")
9+
id("objectbox-publish")
10+
}
811

912
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
1013
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

0 commit comments

Comments
 (0)