|
1 | 1 | plugins {
|
2 | 2 | id 'java'
|
3 |
| - id 'maven-publish' |
| 3 | + id 'signing' |
4 | 4 | id 'idea'
|
5 | 5 | id 'eclipse'
|
6 | 6 |
|
7 | 7 | id 'com.diffplug.spotless' version '6.21.0'
|
8 |
| -} |
9 | 8 |
|
| 9 | + /* We have to use this 3rd party plugin for publishing to MavenCentral because as of AUG-2025 there is no official |
| 10 | + * plugin which supports publishing to MavenCentral Portal. */ |
| 11 | + id "com.vanniktech.maven.publish.base" version "0.34.0" |
| 12 | +} |
10 | 13 |
|
11 | 14 | allprojects {
|
12 | 15 | apply plugin: 'com.diffplug.spotless'
|
@@ -63,86 +66,118 @@ allprojects {
|
63 | 66 | }
|
64 | 67 | }
|
65 | 68 |
|
| 69 | +def configureMavenCentralPublishing(Project project) { |
| 70 | + project.plugins.withId('com.vanniktech.maven.publish.base') { |
| 71 | + project.mavenPublishing { |
| 72 | + publishToMavenCentral(true) // publish automatically after upload to Maven Central |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
66 | 77 | subprojects {
|
67 | 78 | apply plugin: 'java'
|
68 |
| - apply plugin: 'maven-publish' |
69 | 79 | apply plugin: 'idea'
|
70 | 80 | apply plugin: 'eclipse'
|
71 | 81 |
|
72 |
| - group = 'cloud.stackit' |
73 |
| - |
74 |
| - afterEvaluate { project -> |
75 |
| - // only apply to service sub-projects and core |
76 |
| - if (project.path.startsWith(':services:') || project.name == "core" ) { |
77 |
| - // override the version of each service with the ones obtained from the VERSION files |
78 |
| - def versionFile = project.file("VERSION") |
79 |
| - if (versionFile.exists()) { |
80 |
| - try { |
81 |
| - version = versionFile.text.trim() |
82 |
| - } catch (IOException e) { |
83 |
| - version = 'SNAPSHOT' |
84 |
| - logger.error("Could not read VERSION file for project '${project.path}': ${e.message}") |
85 |
| - } |
86 |
| - } else { |
| 82 | + group = 'cloud.stackit.sdk' |
| 83 | + |
| 84 | + // only apply to service sub-projects and core |
| 85 | + if (project.path.startsWith(':services:') || project.name == "core" ) { |
| 86 | + apply plugin: 'signing' |
| 87 | + apply plugin: 'com.vanniktech.maven.publish.base' |
| 88 | + |
| 89 | + // override the version of each service with the ones obtained from the VERSION files |
| 90 | + def versionFile = project.file("VERSION") |
| 91 | + if (versionFile.exists()) { |
| 92 | + try { |
| 93 | + version = versionFile.text.trim() |
| 94 | + } catch (IOException e) { |
87 | 95 | version = 'SNAPSHOT'
|
88 |
| - logger.warn("VERSION file not found in project '${project.path}'. Skipping version setting.") |
| 96 | + logger.error("Could not read VERSION file for project '${project.path}': ${e.message}") |
89 | 97 | }
|
| 98 | + } else { |
| 99 | + version = 'SNAPSHOT' |
| 100 | + logger.warn("VERSION file not found in project '${project.path}'. Skipping version setting.") |
| 101 | + } |
90 | 102 |
|
| 103 | + java { |
| 104 | + withSourcesJar() |
| 105 | + withJavadocJar() |
| 106 | + } |
91 | 107 |
|
92 |
| - publishing { |
93 |
| - publications { |
94 |
| - maven(MavenPublication) { |
95 |
| - artifactId = "stackit-sdk-${project.name}" |
96 |
| - from components.java |
97 |
| - |
98 |
| - pom { |
99 |
| - name.set(project.name) |
100 |
| - description.set("STACKIT Java SDK for the ${project.name} service") |
101 |
| - url.set("https://github.com/stackitcloud/stackit-sdk-java/tree/main/services/${rootProject.name}") |
102 |
| - licenses { |
103 |
| - license { |
104 |
| - name.set("Apache License, Version 2.0") |
105 |
| - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") |
106 |
| - } |
107 |
| - } |
108 |
| - developers { |
109 |
| - developer { |
110 |
| - id.set("stackitcloud") // TODO: not clear which value must be placed here, check this when setting up publishment to Maven Central |
111 |
| - name.set("STACKIT Developer Tools") |
112 |
| - |
113 |
| - } |
| 108 | + // don't fail on missing javadoc strings |
| 109 | + tasks.withType(Javadoc).configureEach { |
| 110 | + options.addStringOption('Xdoclint:none', '-quiet') |
| 111 | + } |
| 112 | + |
| 113 | + publishing { |
| 114 | + publications { |
| 115 | + mavenJava(MavenPublication) { |
| 116 | + artifactId = "${project.name}" |
| 117 | + from components.java |
| 118 | + |
| 119 | + pom { |
| 120 | + name.set(project.name) |
| 121 | + description.set("STACKIT Java SDK for the ${project.name} service") |
| 122 | + url.set("https://github.com/stackitcloud/${rootProject.name}/tree/main/services/${project.name}") |
| 123 | + licenses { |
| 124 | + license { |
| 125 | + name.set("Apache License, Version 2.0") |
| 126 | + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") |
114 | 127 | }
|
115 |
| - scm { |
116 |
| - connection.set("scm:git:git://github.com/stackitcloud/${rootProject.name}.git") |
117 |
| - developerConnection.set("scm:git:ssh://github.com/stackitcloud/${rootProject.name}.git") |
118 |
| - url.set("https://github.com/stackitcloud/${rootProject.name}") |
| 128 | + } |
| 129 | + developers { |
| 130 | + developer { |
| 131 | + id.set("stackitcloud") |
| 132 | + name.set("STACKIT Developer Tools") |
| 133 | + |
119 | 134 | }
|
120 | 135 | }
|
| 136 | + scm { |
| 137 | + connection.set("scm:git:git://github.com/stackitcloud/${rootProject.name}.git") |
| 138 | + developerConnection.set("scm:git:ssh://github.com/stackitcloud/${rootProject.name}.git") |
| 139 | + url.set("https://github.com/stackitcloud/${rootProject.name}") |
| 140 | + } |
121 | 141 | }
|
122 | 142 | }
|
123 |
| - repositories { |
124 |
| - mavenLocal() |
125 |
| - } |
| 143 | + } |
| 144 | + |
| 145 | + repositories { |
| 146 | + mavenLocal() |
126 | 147 | }
|
127 | 148 | }
|
128 | 149 |
|
129 |
| - // only apply to example sub-projects |
130 |
| - if (project.path.startsWith(':examples:')) { |
131 |
| - if (!project.hasProperty('mainClassName')) { |
132 |
| - logger.warn("'mainClassName' property not defined for subproject '${project.path}'. Skipping execution of this task.") |
| 150 | + signing { |
| 151 | + required { |
| 152 | + // signing is only required if the artifacts are to be published to Maven Central |
| 153 | + gradle.taskGraph.hasTask(":services:${project.name}:publishToMavenCentral") || gradle.taskGraph.hasTask(":${project.name}:publishToMavenCentral") |
133 | 154 | }
|
134 | 155 |
|
135 |
| - tasks.register('execute', JavaExec) { |
136 |
| - if (!project.hasProperty('mainClassName')) { |
137 |
| - doLast { |
138 |
| - logger.warn("'mainClassName' property not defined for subproject '${project.path}'. Skipping execution of this task.") |
139 |
| - } |
140 |
| - enabled = false // Disable the task if no main class is specified |
141 |
| - return |
| 156 | + def signingKey = System.getenv("GPG_SIGNING_KEY") ?: findProperty("signingKey") |
| 157 | + def signingPassword = System.getenv("GPG_SIGNING_PASSWORD") ?: findProperty("signingPassword") |
| 158 | + useInMemoryPgpKeys(signingKey as String, signingPassword as String) |
| 159 | + sign publishing.publications.mavenJava |
| 160 | + } |
| 161 | + |
| 162 | + configureMavenCentralPublishing(project) |
| 163 | + } |
| 164 | + |
| 165 | + // only apply to example sub-projects |
| 166 | + if (project.path.startsWith(':examples:')) { |
| 167 | + if (!project.hasProperty('mainClassName')) { |
| 168 | + logger.warn("'mainClassName' property not defined for subproject '${project.path}'. Skipping execution of this task.") |
| 169 | + } |
| 170 | + |
| 171 | + tasks.register('execute', JavaExec) { |
| 172 | + if (!project.hasProperty('mainClassName')) { |
| 173 | + doLast { |
| 174 | + logger.warn("'mainClassName' property not defined for subproject '${project.path}'. Skipping execution of this task.") |
142 | 175 | }
|
143 |
| - mainClass = project.mainClassName |
144 |
| - classpath = sourceSets.main.runtimeClasspath |
| 176 | + enabled = false // Disable the task if no main class is specified |
| 177 | + return |
145 | 178 | }
|
| 179 | + mainClass = project.mainClassName |
| 180 | + classpath = sourceSets.main.runtimeClasspath |
146 | 181 | }
|
147 | 182 | }
|
148 | 183 |
|
|
0 commit comments