@@ -16,13 +16,11 @@ import org.gradle.plugins.signing.Sign
1616import org.gradle.plugins.signing.SigningExtension
1717import org.jreleaser.model.Active
1818
19- // TODO: Refactor all of this into env vars ?
19+ // Props
2020private const val SKIP_PUBLISH_PROP = " skipPublish"
21- private const val SIGNING_KEY_PROP = " signingKey"
22- private const val SIGNING_PASSWORD_PROP = " signingPassword"
2321
22+ // Env vars
2423private const val J_RELEASER_STAGE_ENV_VAR = " JRELEASER_MAVENCENTRAL_STAGE"
25- private const val J_RELEASER_VERSION_ENV_VAR = " JRELEASER_PROJECT_VERSION"
2624private const val J_RELEASER_GROUP_ENV_VAR = " JRELEASER_PROJECT_JAVA_GROUP_ID"
2725private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = " JRELEASER_MAVENCENTRAL_USERNAME"
2826private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = " JRELEASER_MAVENCENTRAL_TOKEN"
@@ -63,7 +61,7 @@ fun Project.skipPublishing() {
6361 * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
6462 * @param githubOrganization the name of the GitHub organization that [repoName] is located in
6563 */
66- fun Project.configurePublishing (repoName : String , githubOrganization : String = "awslabs") { // TODO: USE ENV VARS NOW ?
64+ fun Project.configurePublishing (repoName : String , githubOrganization : String = "awslabs") {
6765 val project = this
6866 apply (plugin = " maven-publish" )
6967
@@ -113,12 +111,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
113111 }
114112 }
115113
116- if (project.hasProperty(SIGNING_KEY_PROP ) && project.hasProperty(SIGNING_PASSWORD_PROP )) {
114+ val gpgSecretKey = System .getenv(J_RELEASER_GPG_SECRET_KEY_ENV_VAR )
115+ val gpgPassphrase = System .getenv(J_RELEASER_GPG_PASSPHRASE_ENV_VAR )
116+
117+ if (! gpgPassphrase.isNullOrBlank() && ! gpgSecretKey.isNullOrBlank()) {
117118 apply (plugin = " signing" )
118119 extensions.configure<SigningExtension > {
119120 useInMemoryPgpKeys(
120- project.property( SIGNING_KEY_PROP ) as String ,
121- project.property( SIGNING_PASSWORD_PROP ) as String ,
121+ gpgSecretKey ,
122+ gpgPassphrase ,
122123 )
123124 sign(publications)
124125 }
@@ -147,28 +148,31 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
147148 */
148149fun Project.configureJReleaser () {
149150 verifyRootProject { " JReleaser configuration must be applied to the root project only" }
151+
152+ var missingEnvVars = false
150153 listOf (
151154 J_RELEASER_STAGE_ENV_VAR ,
152- J_RELEASER_VERSION_ENV_VAR ,
153155 J_RELEASER_GROUP_ENV_VAR ,
154156 J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR ,
155157 J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR ,
156158 J_RELEASER_GPG_PASSPHRASE_ENV_VAR ,
157159 J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR ,
158160 J_RELEASER_GPG_SECRET_KEY_ENV_VAR ,
159- ).map { variable ->
160- if (System .getenv(variable) == null ) {
161- logger.warn(" Skipping JReleaser configuration, missing required env var: $variable " )
162- true
163- } else {
164- false
161+ ).forEach {
162+ if (System .getenv(it).isNullOrBlank()) {
163+ missingEnvVars = true
164+ logger.warn(" Skipping JReleaser configuration, missing or blank required env var: $it " )
165165 }
166- }.any { return }
166+ }
167+ if (missingEnvVars) return
168+
169+ // Get SDK version from gradle.properties
170+ val sdkVersion: String by project
167171
168172 apply (plugin = " org.jreleaser" )
169173 extensions.configure<JReleaserExtension > {
170174 project {
171- version = System .getenv( J_RELEASER_VERSION_ENV_VAR )
175+ version = sdkVersion
172176 }
173177 signing {
174178 active = Active .ALWAYS
@@ -180,7 +184,7 @@ fun Project.configureJReleaser() {
180184 create(" maven-central" ) {
181185 active = Active .ALWAYS
182186 url = " https://central.sonatype.com/api/v1/publisher"
183- stagingRepository(rootProject.layout.buildDirectory.dir(" m2" ).get().toString()) // TODO: Commonize between this and above
187+ stagingRepository(rootProject.layout.buildDirectory.dir(" m2" ).get().toString())
184188 }
185189 }
186190 }
@@ -195,7 +199,7 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic
195199 if (project.extra.has(SKIP_PUBLISH_PROP )) shouldPublish = false
196200
197201 // Validate publishGroupName
198- val publishGroupName = System .getenv(J_RELEASER_GROUP_ENV_VAR ) // TODO: Check if env var is available ?
202+ val publishGroupName = System .getenv(J_RELEASER_GROUP_ENV_VAR )
199203 shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
200204
201205 // Validate publication name is allowed to be published
0 commit comments